Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28630 Discussions

Mixing c++ and Fortran dynamic allocation at runtime

Roberto_Sartori
Beginner
455 Views

Hi,

I have a project divided in many libraries and dlls.Some are written in c++, some other in Fortran. Whai I would like to understand is if there can be problems by managing dynamic memory (allocate - deallocate, new - delete) with both c++ and Fortran at runtime.

Some Fortran DLL includes a c++ static library which allocates and deallocates some data which is used by fortran code. This could generate memory leaks? or c runtimes has no problems with fortran runtimes? does the RTL of different languages manages the same heap or does they create a separate Heap for c++ and fortran RTL?

The only rule I follow is to set DLL (multithread) runtime libraries for both c++ and Fortran and to avoid mixed language allocations/deallocations (I mean, If I allocate y with 'new' in c++ I will deallocate it with delete in c++, not with DELETE in fortran). Is this enought or there are some other important rules to keep in mind when mixing languages?

0 Kudos
2 Replies
Les_Neilson
Valued Contributor II
455 Views
As long as you keep to your rule you should be ok.
I have many mixed language exes and libraries,and a lot of array allocation and re-allocation done in Fortran without problem including passing arrays between languages.
There should be no memory leaks from fortran allocations - unless there is a compiler bug :-) C and C++ allocations however need to be watched.

Les

0 Kudos
Roberto_Sartori
Beginner
455 Views
Quoting - Les Neilson
As long as you keep to your rule you should be ok.
I have many mixed language exes and libraries,and a lot of array allocation and re-allocation done in Fortran without problem including passing arrays between languages.
There should be no memory leaks from fortran allocations - unless there is a compiler bug :-) C and C++ allocations however need to be watched.

Les

many thanks Les

0 Kudos
Reply