Intializing Variables for Use Across DLL

Intializing Variables for Use Across DLL

All,

I'm working on some legacy software and we have a DLL with one external function: doSomeMath( Data ). Where Data is really multiple arguments with several different large derived types. Internally in doSomeMath the Data is manipulated, memory is allocated and intialization routines are called and there is finally a function computeValues( manipluatedData ). doSomeMath is called several times from a C++ program and each time Data is remanipulated in a non-unique way. What would be the best way to make a function initializeData( Data ) so that I can call computeValues( ) from the C++? I'd laso think this would be more flexible because I can call computeDifferentValues( ) without any re-initialization.

I can think of returning manipulatedData to the C++ and passing it each time or possibly storing manipulatedData as global variables. If I use the globals approach I'd declare manipulated data with the COMMON attribute, right? The first way seems inefficient, the second way seems unsafe. I'm still new to Fortran and programming in general so any advice is greatly appreciated. Thanks.

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

If you want to use globals, use module variables rather than COMMON. This will allow you to use allocatable arrays. But consider instead the use of "handles" - pointers to structures where you keep context data that can be passed back and forth. This will permit possible parallelization in the future.

Steve - Intel Developer Support

Steve,

Thanks for your quick reply. Is the best way to create the handles by returning a C_PTR that points to C_LOC( manipulatedData ) to the C++, then recovering the structure using C_F_POINTER in computeValues( )? Or, if the C++ never needs to manipulate the data, can I just use FORTRAN pointers and the LOC( ) function?

I like the first idea better, whether or not the C++ touches the data. I am not sure what you mean by "FORTRAN pointers" - if you mean the "POINTER (a,b)" syntax, that's an extension.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today