I was recently evaluating the Silverfrost Fortran 95
compiler compiler for .NET. This appears to be a capable implementation of a fortran compiler for the .NET platform. One of my main test piece of code was a smallish fortran routine (approx 360 lines) that calculated a geodetic height. The fortran functions were provided with an input latitude and longitude and calculated the geodetic height above the earths surface.
Not much of real interest there, apart from the fact that the front end was written in C# and the back end which was all fortran was compiled into a DLL which was referenced from the front end project. However, to perform the calculation, the fortran function had to open and read coefficient data into memory from a file containing 65338 records and each record contained 2 integers and 4 doubles.
Thats 2*4 + 4*8 bytes per record = 40 Bytes per record.
65338 records * 40 bytes = 2, 613, 520 bytes or 2552Kb or 2.5Mb
Both projects (client and backend) compiled ok, as expected. The Client was run and some data was entered. Once the C# code called the Fortran backend, an unhandled exception was immediately raised of type
"System.StackoverflowException"
The help text for System.StackoverflowException states that it is typically thrown in the case of very deep or unbounded recursion. However I had no recursion, so it must have been due to the amount of data that the fortran backend was allocating to store these large coefficient arrays.
A bit of research on the net did not really help very much, so a bit more searching around MSDN found a tool named EDITBIN. This tool (The Microsoft COFF Binary file Editor) allows you to modify certain characteristics of COFF binary files, including executables and DLL's.
It has an associated tool named DUMPBIN to obtain information about COFF files.
After examination of my .NET generated fortran backend DLL, the size of stack reserve was shown to be 100000.This number is in hex and is therefore 1048576 bytes or 1024Kb.
I ran the
editbin command on my 2 files in my assembly
editbin/stack:3000000 GEOIDBackEnd.DLL
editbin/stack:3000000 GEOIDFrontEnd.EXE
So I have now increased my default stacksize on my 2 executables and am able to run my magnificent fortran coefficient mathematical engine.
To automate this process if you are debugging, you can create a .BAT file containing the above lines and reference that from within the Visual Studio .NET project Options/Build Events/Post Build Step field.