- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Our application has a C# front-end and a Fortran DLL backend for numerical computations.
I'd like to pass arrays allocated in Fortran back to C#, while avoiding copying of the arrays.
Is this possible? If so, can someone provide a simple example.
Thanks,
Kevin
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kevin,
We use the same approach you describe in our engineering software: a C# GUI calling routines in Fortran DLLs. We have had good success declaring arrays in the C# method before calling the Fortran subroutine, and returning results or data from a file in the passed array. We pass the arrays by reference rather than by value, which I think avoids the issue of copying the array you mentioned. If we use a multi-dimensional array, we transpose the array in the C# code before calling the Fortran subroutine. We also pass integer variables with the array row and column dimensions so that we can fully declare the array in the Fortran subroutine.
Depending on the data returned from the Fortran routine in the array, such as values from a file or from a calculation, we either determine the required array size or get an estimate of the needed array size to declare the array in the C# method. There is error checking in the Fortran subroutine to avoid going out of bounds in the array. Could you use this approach?
Regards,
Greg
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page