delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/15/14:47:47

From: "Rafael García" <rafael AT geninfor DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: heap fragmentation
Date: Mon, 15 Nov 1999 18:55:18 +0100
Organization: CTV/JET
Lines: 54
Message-ID: <80ph6k$t7v$1@lola.ctv.es>
NNTP-Posting-Host: infon599.jet.es
X-Trace: lola.ctv.es 942688276 29951 195.55.158.87 (15 Nov 1999 17:51:16 GMT)
X-Complaints-To: usenet AT lola DOT ctv DOT es
NNTP-Posting-Date: 15 Nov 1999 17:51:16 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I have a program that reads a file loading each line into dynamic memory
with something like this:

...
text[nline]=malloc(width);
...
strcpy(text[nline],buf);
nline++;
...


during load, there may be some line that don't fix in the prepared width so
after reading all the file I need to start over changing to the extended
width (all lines must have max width), so I free all lines:

for (n=0;n<nlines;n++) free(text[n]);


well, this seems to have a waste effect over de heap because when I try to
calculate number of lines available
now, it don't count freed lines.

My question is:  is there any method to 'pack'/'unfragment' the heap so I
can know the really amount of used memory?



this is my function to look free memory:


#if defined(__GNUC__) && !defined(UNIX)
long memlibre(void) {
   static long inicialmente=0;
   long limite;
   static long limiteinicial;
   long consumido;

   if (!inicialmente) {
      inicialmente=_go32_dpmi_remaining_physical_memory();
      limiteinicial=(long)sbrk(0);
      }
   limite=(long)sbrk(0);
   consumido=limite-limiteinicial;                    // used memory
   return inicialmente-consumido;                     // initial - used :
free
   }
#endif



Thanks all
Rafael García


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019