Article View: comp.os.ms-windows.programmer.tools
Article #738Re: Replacement for malloc using GlobalAlloc
From: Noel S. Gorelick
Date: Tue, 17 Nov 1992 02:08
Date: Tue, 17 Nov 1992 02:08
35 lines
2095 bytes
2095 bytes
Bill Whedon (whedon@netcom.com) wrote:
> Here's the summary I promised. The answers I got were mixed. Advice to
> keep using malloc, advice to use _fmalloc, neither of which solved the
> original problem (corruption of a linked list). The most useful was from
> raymondc@microsoft.com, who sent me a fix for the myfree() routine which
> stopped my memory leak. Both routines follow this note.
>
> void *mymalloc(size_t bytes)
> ...
> h = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,(DWORD)bytes);
> ...
>
> void myfree(void *p)
> ...
> h = (GLOBALHANDLE)SELECTOROF((LPVOID)p);
> ...
Question 1) What is SELECTOROF()? I am assuming it is the equivalent of
GlobalHandle()?
Question 2) What do you do about running out of HANDLES? It has been my
expereince, and I have had it confirmed by a few other
programmers, that you only get to allocate about 8000 handles,
using GlobalAlloc, before you start getting incoherent results...
Is there any way around this, short of allocating large blocks
and doing your own memory management?
And if there isn't, does someone have a set of routines to do
this allocation yet?
Noel
--
"You want it should sing too?" | /* Yeah we got dogs and Valvoline
ngorelic@speclab.cr.usgs.gov | Its a pretty damn good time. */
"Life is pain. Anyone that tells you different is trying to sell you something"
Technical Details
Message-ID:
<1992Nov17.020804.20835@riacs.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!uwm.edu!cs.utexas.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!riacs!speclab.cr.usgs.gov!ngorelicReferences:
<1992Nov14.092011.29891@netcom.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.tools,comp.windows.ms.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!uwm.edu!cs.utexas.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!riacs!speclab.cr.usgs.gov!ngorelic From: ngorelic@speclab.cr.usgs.gov.cr.usgs.gov (Noel S. Gorelick) Subject: Re: Replacement for malloc using GlobalAlloc Message-ID: <1992Nov17.020804.20835@riacs.edu> Sender: news@riacs.edu Reply-To: ngorelic@speclab.cr.usgs.gov Organization: MercWorks, Denver X-Newsreader: TIN [version 1.1 PL6] References: <1992Nov14.092011.29891@netcom.com> Date: Tue, 17 Nov 92 02:08:04 GMT Lines: 35