delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/01/06:48:34

Date: Sun, 1 Mar 1998 13:47:26 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Radar <p_radar AT hotmail DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Freeing memory
In-Reply-To: <01bd43ac$ae0a7a00$LocalHost@server>
Message-ID: <Pine.SUN.3.91.980301134035.13547Q-100000@is>
MIME-Version: 1.0

On 27 Feb 1998, Radar wrote:

> I have a trouble with freeing memory. I use malloc to allocate memory and
> free to return allocated space. But the problem is that after free it
> doesn't raise Free physical memory. I watch
> __dpmi_get_free_memory_information to get total number of free pages.

This is explained in detail in the DJGPP FAQ list (v2/faq210b.zip from 
the same place you get DJGPP), section 15.2.  When you call `free', the 
freed block is not returned to the system, it is added to the pool of 
free blocks which `malloc' and `free' maintain, and is reused for future 
allocations.

> Could someone help me, how to free memory, because I quickly run out of
> physical memory and the program swaps to disk.

This has nothing to do with free memory reported by the DPMI functions.  
The blocks which you free *are* available for subsequent allocations by 
`malloc'.  So the fact that your program begins to page would mean that 
there is some memory leak in your program somewhere.  Another possibility 
is that you are allocating and freeing memory in a way that causes memory 
fragmentation.  Please read Chapter 15 of the FAQ, for more details about 
some related subtleties.

> ' Total number of free pages : 3568
> data= (double *) malloc(100000*sizeof(double));
> '  Total number of free pages : 3567 ??

This is also explained in section 15.2 of the FAQ.  Memory is not paged 
in until you actually touch it.  Try `calloc' instead of `malloc' and see 
a big difference.

- Raw text -


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