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

Stack reserve size in DLL vs EXE

Nils_O_1
Beginner
1,956 Views

I've converting a Fortran 77 code that has lots of stack memory utilization from an executable to a DLL (Windows).  For example there are hundreds (thousands) of arrays such as this:

      COMMON/A1/  CU1(LCM,KCM),     CU2(LCM,KCM),
     2            UUU(LCM,KCM),     VVV(LCM,KCM),  WWW(LCM,0:KCM),
     3             DU(LCM,KCM),      DV(LCM,KCM),
     4             FX(LCM,KCM),      FY(LCM,KCM)

After modifying the stack reserve size to be as large as possible the program compiles and runs as a standalone executable.  When it's compiled as a DLL it crashes with:

Unable to load DLL 'LIB.dll': Not enough storage is available to process this command. (Exception from HRESULT: 0x80070008)

What is the difference in a DLL and EXE that is causing this?

0 Kudos
4 Replies
IanH
Honored Contributor III
1,956 Views

Common block things are normally (perhaps always) statically allocated, not stack allocated.

I don't think the stack reserve setting for a DLL is used at all - the settings for the initial thread (and I think subsequent threads that specify a default stack size) are always taken from the executable file for the process

I suspect that the static allocation required by the DLL is simply too large to fit in the available gaps in the process address space once your exe (including its stack), and all the other DLL's that typically get loaded, has been laid out in memory.

Are you compiling for 32 bit Windows?  64 bit windows removes many of the limitations in this area, but not all.

0 Kudos
Steven_L_Intel1
Employee
1,956 Views

Ian is correct that setting stack size in a DLL does nothing. This is an EXE property only. As Ian suggests, the problem is more likely to be static allocation snd insufficient address space. Note that there is a practical limit of 1.75GB or so for static code and data, even in a 64-bit application (on Windows).

0 Kudos
Nils_O_1
Beginner
1,956 Views

This information is great.  However, I've changed the static allocation size to be very small (at least by changing the variable size) and the application is still unable to load the DLL with the same error.  I also modified the target EXE to increase the stack reserve size also without effect (an interesting side effect was that as I increased the stack reserve size with editbin /stack the application became gradually slower and unresponsive).

Is there an easy way to determine the static allocation size during the compilation and linking process?

The Fortran DLL is being loaded into a .Net application.  Are you aware of anything in this interaction that would cause the issue?

0 Kudos
Steven_L_Intel1
Employee
1,956 Views

If you ask for a link map, you can get the static size from that. But I am going to guess that this isn't the real problem - it is something in the .NET environment that is not working properly.

0 Kudos
Reply