rkitts@netcom.COM (Rick Kitts) (03/12/91)
I am working on a program which make heavy use of malloc() and free(). Apparently memory which is allocated and deallocated is never coalesced which of course is leading me fragmented memory. A dump of the heap using heapwalk() (from MicroSoft) indicates that I have many K of free memory, but it is all in pieces which are too small to be useful. Does anyone know of anyway to coalesce this memory? I am hoping to not have to write my own memory manager, but it's starting to look like I might. BTW, I am using Microsloth C (painfully slow) version 6.0. Any help would be greatly appreciated. ---Rick rkitts@netcom.com
ekalenda@cup.portal.com (Edward John Kalenda) (03/13/91)
>I am working on a program which make heavy use of malloc() and free(). >Apparently memory which is allocated and deallocated is never coalesced >which of course is leading me fragmented memory. A dump of the heap >using heapwalk() (from MicroSoft) indicates that I have many K of free >memory, but it is all in pieces which are too small to be useful. > >Does anyone know of anyway to coalesce this memory? I am hoping to not >have to write my own memory manager, but it's starting to look like I >might. > >BTW, I am using Microsloth C (painfully slow) version 6.0. Any help would >be greatly appreciated. > >---Rick > >rkitts@netcom.com I had the same problem in an app I wrote for a client. The malloc() function DOES coalesce free memory IF the two free blocks are adjoining in memory. The trouble is that there is a tendancy for blocks still in use to be in the way. The most painful way this happens is that fopen() uses malloc() to create some control and buffer structures, which are not freed by close(). I had to write a memory manager and IO library replacement package so I would have a handle based system similar to the Mac. This let me coalesce memory whenever I needed to. The hassle was that I had to pre-allocate the table of handles ahead of time so they would not be in the middle of the other memory blocks. Have fun. I didn't. :-( Ed ekalenda@cup.portal.com