View previous topic :: View next topic |
Author |
Message |
DrTip
Joined: 01 Aug 2006 Posts: 74 Location: Manchester
|
Posted: Thu Apr 10, 2008 11:23 am Post subject: heap corrupt error when using .net array valued functions |
|
|
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.
Code: |
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
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 |
|
Back to top |
|
|
DrTip
Joined: 01 Aug 2006 Posts: 74 Location: Manchester
|
Posted: Thu May 01, 2008 8:02 am Post subject: |
|
|
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 |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7926 Location: Salford, UK
|
Posted: Thu May 01, 2008 12:12 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Fri May 02, 2008 7:13 am Post subject: |
|
|
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 |
|
Back to top |
|
|
DrTip
Joined: 01 Aug 2006 Posts: 74 Location: Manchester
|
Posted: Fri May 02, 2008 9:23 am Post subject: |
|
|
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 |
|
Back to top |
|
|
|