Newsgroups: comp.lang.pascal
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!sun1.ruf.uni-freiburg.de!hartnegg
From: hartnegg@sun1.ruf.uni-freiburg.de (Klaus Hartnegg)
Subject: Re: Defragmenting the heap in TP 5.5
Message-ID: <1991Jun5.083707.19706@sun1.ruf.uni-freiburg.de>
Organization: Rechenzentrum der Universitaet Freiburg, Deutschland
References: <9106040138.AA07202@lux.sait.edu.au>
Date: Wed, 5 Jun 91 08:37:07 GMT
Lines:       27

et891856@LUX.SAIT.EDU.AU (et891856) writes:

>I'm in the middle of writing a text windowing unit which uses the heap to
>store overlayed parts of the screen and i'm running into problems with heap
>overflow.  A little investigating with breakpoints shows the memavail variable
>staying pretty constant but the maxavail variable dropping all the time, even
>though the heap memory allocated is released later on.

>This kind of points to fragmentation of the heap, my question is :
>Is there anyway of defragmenting the heap so my unit doesn't crash ?

This can't be done because all pointers would have to be updated
but it's impossible to find them all. If you know all your 
variables you can perhaps do it yourself but that's complicated.

Try allocating memory in larger blocks, for example multiples of
16 bytes. You can even cause Turbo-Pascal to do this automatically
It's described somewhere in the manual. I think it can be done by 
replacing the getmem and freemem procedures.

Klaus
-- 
--------------------------------------------------------------------------
Klaus Hartnegg, Kleist-Str. 7, D-7835 Teningen, Germany | include standard
Bitnet : hartnegg@dfrruf1 or hartnegg@cernvm            | disclaimer here!
Internet : hartnegg@ibm.ruf.uni-freiburg.de             |  
