home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / mswindo / programm / tools / 1407 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.5 KB  |  57 lines

  1. Newsgroups: comp.os.ms-windows.programmer.tools,comp.windows.ms.programmer
  2. Path: sparky!uunet!gumby!wupost!csus.edu!netcom.com!whedon
  3. From: whedon@netcom.com (Bill Whedon)
  4. Subject: generic replacement for malloc and free using Global...?
  5. Message-ID: <1992Nov12.203727.11519@netcom.com>
  6. Followup-To: poster
  7. Keywords: malloc free GlobalAlloc GlobalFree
  8. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  9. Date: Thu, 12 Nov 1992 20:37:27 GMT
  10. Lines: 45
  11.  
  12. I wonder if anyone has a generic replacement for malloc and free which make
  13. use of GlobalAlloc and GlobalFree?  I did those up, but for some reason, the
  14. memory thus allocated doesn't seem to be getting released properly, even
  15. though I am careful to execute one free for each malloc.  As an offshoot of
  16. this, my memory slowly goes down in Windows until I terminate my app, at
  17. which time it all appears to come back. Any ideas?  Working procs?   Please
  18. email me and I will summarize, as I know of at least two other people who
  19. want this stuff.  I suspect there're more...
  20. Thanks,
  21. Bill Whedon   whedon@netcom.com
  22.  
  23. P.S.  My attempt follows (assume appropriate #include stuff):
  24.  
  25.  
  26. void *mymalloc(size_t bytes)
  27. {
  28.    void *p;
  29.    HANDLE h;
  30.    h = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,(DWORD)bytes);
  31.    if (h)
  32.       p = (void *)GlobalLock(h);
  33.    else
  34.       p = NULL;
  35.    return p;
  36. }
  37.  
  38. void myfree(void *p)
  39. {
  40.    HANDLE h;
  41.    if (NULL != p)
  42.    {
  43.       h = (GLOBALHANDLE) LOWORD((LONG) p);
  44.       GlobalUnlock(h);
  45.       GlobalFree(h);
  46.    }
  47.    return;
  48. }
  49.  
  50.  
  51. -- 
  52. -- If I ain't programmin' I ain't awake! --
  53.  
  54.  
  55.  
  56.  
  57.