Silverfrost Forums

Welcome to our forums

heap corrupt error when using .net array valued functions

10 Apr 2008 10:23 #3025

Apologies for lack of posts over last few months have been doig other things:

I have been playing around with some array valued functions. I want these functions to be in a DLL. The length of the array should be varaible and not known until called.

I have got this working in WIN32 after som faffing. but when I target the .NET framework I get :

30: Storage heap is corrupt

the full exception is

exception this is thrown bSalford.Fortran.RuntimeException was unhandled Message='30: Storage heap is corrupt' Source='ftn95lib' StackTrace: at Salford.Fortran.RTLibrary.TempFree(Void* ptr) at Harness.HARNESS() in C:\Documents and Settings\ctipton\My Documents\Visual Studio 2005\Projects\FTN95Logit\Harness\Harness.F95:line 34

it appears to be the actual function itself which is the only funtion in the DLL.

function logit(costs, lambda)
 assembly_interface(name='Logit')

  real costs(:)
  real lambda 
  real logit(size(costs))
  

   logit= exp(-lambda*costs)/sum(exp(-lambda*costs))
   

end function
 

this is the calling code

program Harness
 

  real cost(4) 
  real lambda 

  integer i
  
   interface
  
    function logit(costs,lambda)
        real costs(:)
        real lambda 
        real logit(size(costs))
    end function 
   end interface 
  
  
  cost = 10
  write (*,*) cost
  
  
  lambda = 0.1
  
  write(*,*) logit(cost,lambda)
    
  
  
  
  call get_key@(i)

  

end program 

This work fine in win32

is it something to do with .NET having arrays stored on the heap and I therefore need to use an allocate statement and a pointer of some sort?

I get the same error if I call the function from C#.

Carl

1 May 2008 7:02 #3101

All

I am a little disappointed there has been no response on this.

Am I doing somethign obviously wrong or is there just too much to do patching 5.21

Carl

1 May 2008 11:12 #3105

All that I can suggest is that you try using a subroutine argument rather than a function to return the result.

Basically it looks like an FTN95 bug but it will be extremely difficult to track and fix.

2 May 2008 6:13 #3117

Carl,

You want a response; I hate that form of programming. To me you should have defined the memory requirement before you called the the function. I may be misinterpreting your example, but I have seen coding examples using pointers, where the memory requirement of a function result is allocated by the function. It just doesn't look the right way to manage memory. I'm with Paul, allocate the memory for the array, use a subroutine and the argument definition becomes quite simple.

John C

2 May 2008 8:23 #3119

John

Your suggestion would be how I would work round this normally, but doesn't fit particularly neatly in a wider .net context where everything is an object.

The function should actually be called by a c# main executable.
This is just the the natural way a .net array valued function would work. ( if I had coded it in C# say)

anyway thanks for the reply

Carl

Please login to reply.