forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

heap corrupt error when using .net array valued functions

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
DrTip



Joined: 01 Aug 2006
Posts: 74
Location: Manchester

PostPosted: Thu Apr 10, 2008 11:23 am    Post subject: heap corrupt error when using .net array valued functions Reply with quote

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
View user's profile Send private message
DrTip



Joined: 01 Aug 2006
Posts: 74
Location: Manchester

PostPosted: Thu May 01, 2008 8:02 am    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Thu May 01, 2008 12:12 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Fri May 02, 2008 7:13 am    Post subject: Reply with quote

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
View user's profile Send private message
DrTip



Joined: 01 Aug 2006
Posts: 74
Location: Manchester

PostPosted: Fri May 02, 2008 9:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group