Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DLL and memory allocation problems

0 views
Skip to first unread message

Craig Heading

unread,
Nov 10, 1997, 3:00:00 AM11/10/97
to

I have a problem in a DLL which is used by all of our programs.
Everything works fine unless the first program (the one which loads the
DLL) is terminated before every other program.
The DLL allocates memory buffers using malloc (I did previously use
GlobalAlloc which I think experienced the same problem, but GlobalAlloc
caused other problems which malloc fixed - namely I need 16000
dynamically allocated pointers which is more than the number of
available handles).
I think what is happening is that Windows is freeing the memory
automatically when the main program closes, even though (a) the DLL is
still running (load count!=0) and (b) the .DLL allocated the memory. Is
there any way my DLL can allocate memory which remains valid in this
situation?
Also, is there anyway a DLL can tell which program is calling it as that
may be another possibility.

any help greatly appreciated.
craig

--
----------------------------------------------------------------------
_--_|\ From: Craig Heading
/ \ Mudgee NSW Australia
\_.--._/ email: cr...@winsoft.net.au
v Phone: (063) 72 4548
----------------------------------------------------------------------

David Brabant

unread,
Nov 26, 1997, 3:00:00 AM11/26/97
to

> I have a problem in a DLL which is used by all of our programs.
> Everything works fine unless the first program (the one which loads the
> DLL) is terminated before every other program.
> The DLL allocates memory buffers using malloc (I did previously use
> GlobalAlloc which I think experienced the same problem, but GlobalAlloc
> caused other problems which malloc fixed - namely I need 16000
> dynamically allocated pointers which is more than the number of
> available handles).
> I think what is happening is that Windows is freeing the memory
> automatically when the main program closes, even though (a) the DLL is
> still running (load count!=0) and (b) the .DLL allocated the memory. Is
> there any way my DLL can allocate memory which remains valid in this
> situation?
> Also, is there anyway a DLL can tell which program is calling it as that
> may be another possibility.

You are playing in the 16bit world, aren't you ?
The memory allocated in a DLL belongs to the
executable that first loaded it unless you
do the allocation with the GMEM_SHARE flag.
In this case, the memory belongs to the DLL itself.
But, of course, that implies that you use GlobalAlloc
to allocate your memory.

David


0 new messages