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

freelibrary - dll

fernando_gmu
Beginner
472 Views
I am new in the buisness of doing DLL's. I searched the forum and I didn't find any answer to my problem or so I think.

I have a two large fortran codes that I have ported to windows from unix. These codes are fortran 77, and they don't do any dynamic allocation of memory. The arrays are defined as in the old times.

I made two dll with each code.

I have a main application, also fortran, from where I want to use these dll's.

First I load one dll with loadlibrary(). When this dll finishes, I free the dll with freelibrary(). After this I tried to load the second dll, but I can't. The error reported by the GetLastError says:

"Error: Not enough storage is available to process this command."

I know that if don't load the first dll, I can load the second one without any problem.

My guess is that the memory from the dll I loaded first is not free at the time I try to load the second dll. But this is just my guess.

If any one can give me a help I will be great.

The following is the code to load and free the dll's:

========================================================
....
p = loadlibrary("my.dll"C)
if (p == 0) then
call Report_Sys_Error()
type *, "Error occurred opening my.dll"
type *, "Program aborting"
return
endif

q = getprocaddress(p, "MY_SUB"C)
if (q == 0) then
type *, "Error occurred finding MY_SUB"
type *, "Program aborting"
return
endif

iret = MY_SUB()

! release the library
status = freelibrary(p)
print *, "freelibrary status was: ", status

....
===============================================================

Thanks

Fernando
0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
472 Views
Hmmm. The best I can suggest at the moment is:

- Start the debugger
- place breakpoint(s) before and after dll load
- Open Debug/Windows/Modules and watch the loaded modules in the address space

Does the first dll get correctly removed from the address space?

Note that, if you use LoadLibrary/GetProcAddress/FreeLibrary ("dynamic binding"), you should not link with mydll.lib ("static binding").

Jugoslav
0 Kudos
fernando_gmu
Beginner
472 Views
Hi Jugoslav,

I tried your suggestion, and the dll is removed from the address space.
That means that the allocated memory is free, isn't it?
Any other idea? I am really lost in this one.

Thanks for your swift answer.

regards,

Fernando
0 Kudos
Jugoslav_Dujic
Valued Contributor II
472 Views
Strange. Have you tried to use static binding (the simpler one)? It's rather desperate idea, because it will assume that two libraries can fit into the address space where one can't but nevertheless...

Is the amount of data these two dlls use really that big? Maybe the "out of memory" is just a red herring?

Jugoslav
0 Kudos
fernando_gmu
Beginner
472 Views
Yes, the amount of memory is big. But, it can be I am looking in the wrong direction.

I will try the static binding and see what happen.

Thanks again,

Fernando
0 Kudos
Reply