Article View: comp.os.ms-windows.programmer.tools
Article #779Re: Replacement for malloc using GlobalAlloc
From: Russ Poffenberger
Date: Mon, 23 Nov 1992 20:53
Date: Mon, 23 Nov 1992 20:53
43 lines
2718 bytes
2718 bytes
Noel S. Gorelick (ngorelic@speclab.cr.usgs.gov.cr.usgs.gov) wrote:
: 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?
Yes, there is a limitation on the total number of handles, so you do need to
exercise caution. I also believe that the minimum allocation for GlobalAlloc
is like 4K, so even when allocating something smaller, 4K is reserved. A better
solution is to write a container malloc/free that GlobalAlloc's 4K chunks,
then doles those out, maintaining its own management for the 4K chunks. I
believe that Borland's routines may do some of this type of thing in malloc
and free.
Russ Poffenberger DOMAIN: poffen@sj.ate.slb.com
Schlumberger Technologies ATE UUCP: {uunet,decwrl,amdahl}!sjsca4!poffen
1601 Technology Drive CIS: 72401,276
San Jose, Ca. 95110 Voice: (408)437-5254 FAX: (408)437-5246
Technical Details
Message-ID:
<1992Nov23.205341.3127@sj.ate.slb.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!ut-emx!slcs.slb.com!leo.asc.slb.com!sjsca4!poffenReferences:
<1992Nov17.020804.20835@riacs.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!ut-emx!slcs.slb.com!leo.asc.slb.com!sjsca4!poffen From: poffen@sj.ate.slb.com (Russ Poffenberger) Newsgroups: comp.os.ms-windows.programmer.tools,comp.windows.ms.programmer Subject: Re: Replacement for malloc using GlobalAlloc Message-ID: <1992Nov23.205341.3127@sj.ate.slb.com> Date: 23 Nov 92 20:53:41 GMT References: <1992Nov17.020804.20835@riacs.edu> Sender: news@sj.ate.slb.com Followup-To: comp.os.ms-windows.programmer.tools,comp.windows.ms.programmer Organization: Schlumberger Technologies, ATE division, San Jose, Ca. Lines: 43 X-Newsreader: TIN [version 1.1 PL7]