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 

Passing array elements in .NET

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



Joined: 20 Nov 2006
Posts: 31

PostPosted: Fri Jan 12, 2007 12:07 pm    Post subject: Passing array elements in .NET Reply with quote

I have upgraded to FTN95 v5.01 in order to build our libraries compatible for VS2005. I am therefore using /clr /clr_ver 2 and dbk_link2.

I have code that passes a .NET structure array to a Fortran array and in my existing code I did this by passing an array reference arr(1).

In v5.01 I now get an error: *** Elements of .NET arrays cannot be passed as arguments.

If I remove the (1) I get the error: *** In the INTERFACE to PERCN3 (from MODULE SURF_F77), the 14th dummy argument (WW) was of type REAL(KIND=2), whereas the actual argument is of type OBJECT('System.Double[]')

How do I pass a reference to a .NET array to Fortran?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Jan 12, 2007 7:11 pm    Post subject: Reply with quote

This restriction has been added to FTN95 because of the problem of .NET garbage collection. If garbage collection occurs whilst the routine is running then the array will probably be moved and the reference to it will nolonger be valid.

Previously the code may have worked (particularly if there was no IO involved) but it will have been unsafe. Any IO is likely to trigger garbage collection.
Back to top
View user's profile Send private message AIM Address
dbradly



Joined: 20 Nov 2006
Posts: 31

PostPosted: Mon Jan 15, 2007 10:30 am    Post subject: Reply with quote

Does this mean I cannot pass a .NET array reference to Fortran, or is there an alternative method?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Tue Jan 16, 2007 10:07 pm    Post subject: Reply with quote

Yes it does mean this. You could use /IGNORE <n> for this error but the code will be unsafe.

Basically you should not pass back (by reference) anything that the .NET garbage collector might move whilst you are in the routine. Fortran has no way of knowing that the .NET object may have moved and needs to be written back to a different address. FTN95 tries to prevent you from doing this.
Back to top
View user's profile Send private message AIM Address
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