🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #5156

Re: Defragmenting memory

#5156
From: Edward John Kalenda
Date: Tue, 12 Mar 1991 21:09
34 lines
1808 bytes
>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
Technical Details
Message-ID: <40064@cup.portal.com>
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!rutgers!sun-barr!apple!portal!cup.portal.com!ekalenda
References: <27832@netcom.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!rutgers!sun-barr!apple!portal!cup.portal.com!ekalenda
From: ekalenda@cup.portal.com (Edward John Kalenda)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Defragmenting memory
Message-ID: <40064@cup.portal.com>
Date: 12 Mar 91 21:09:20 GMT
References: <27832@netcom.COM>
Distribution: na
Organization: The Portal System (TM)
Lines: 34