home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / mswindo / programm / tools / 1493 < prev    next >
Encoding:
Internet Message Format  |  1992-11-23  |  2.6 KB

  1. Path: sparky!uunet!cs.utexas.edu!ut-emx!slcs.slb.com!leo.asc.slb.com!sjsca4!poffen
  2. From: poffen@sj.ate.slb.com (Russ Poffenberger)
  3. Newsgroups: comp.os.ms-windows.programmer.tools,comp.windows.ms.programmer
  4. Subject: Re: Replacement for malloc using GlobalAlloc
  5. Message-ID: <1992Nov23.205341.3127@sj.ate.slb.com>
  6. Date: 23 Nov 92 20:53:41 GMT
  7. References: <1992Nov17.020804.20835@riacs.edu>
  8. Sender: news@sj.ate.slb.com
  9. Followup-To: comp.os.ms-windows.programmer.tools,comp.windows.ms.programmer
  10. Organization: Schlumberger Technologies, ATE division, San Jose, Ca.
  11. Lines: 43
  12. X-Newsreader: TIN [version 1.1 PL7]
  13.  
  14. Noel S. Gorelick (ngorelic@speclab.cr.usgs.gov.cr.usgs.gov) wrote:
  15. : Bill Whedon (whedon@netcom.com) wrote:
  16. : > Here's the summary I promised.  The answers I got were mixed.  Advice to
  17. : > keep using malloc, advice to use _fmalloc, neither of which solved the
  18. : > original problem (corruption of a linked list).  The most useful was from
  19. : > raymondc@microsoft.com, who sent me a fix for the myfree() routine which
  20. : > stopped my memory leak.  Both routines follow this note.  
  21. : >
  22. : > void *mymalloc(size_t bytes)
  23. : > ...
  24. : >    h = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,(DWORD)bytes);
  25. : > ...
  26. : > 
  27. : > void myfree(void *p)
  28. : > ...
  29. : >       h = (GLOBALHANDLE)SELECTOROF((LPVOID)p);
  30. : > ...
  31. : Question 1)   What is SELECTOROF()?  I am assuming it is the equivalent of
  32. :               GlobalHandle()?
  33. : Question 2)   What do you do about running out of HANDLES?  It has been my
  34. :               expereince, and I have had it confirmed by a few other 
  35. :               programmers, that you only get to allocate about 8000 handles,
  36. :           using GlobalAlloc, before you start getting incoherent results...
  37. :           Is there any way around this, short of allocating large blocks 
  38. :           and doing your own memory management?
  39. :           And if there isn't, does someone have a set of routines to do
  40. :           this allocation yet?
  41.  
  42. Yes, there is a limitation on the total number of handles, so you do need to
  43. exercise caution. I also believe that the minimum allocation for GlobalAlloc
  44. is like 4K, so even when allocating something smaller, 4K is reserved. A better
  45. solution is to write a container malloc/free that GlobalAlloc's 4K chunks,
  46. then doles those out, maintaining its own management for the 4K chunks. I
  47. believe that Borland's routines may do some of this type of thing in malloc
  48. and free.
  49.  
  50. Russ Poffenberger               DOMAIN: poffen@sj.ate.slb.com
  51. Schlumberger Technologies ATE   UUCP:   {uunet,decwrl,amdahl}!sjsca4!poffen
  52. 1601 Technology Drive        CIS:    72401,276
  53. San Jose, Ca. 95110             Voice: (408)437-5254  FAX: (408)437-5246
  54.