cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/04/10:09:06

Date: Sun, 4 Jul 1999 17:06:58 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Seunghwan Ji <shjee AT nexgen DOT co DOT kr>
cc: djgpp AT delorie DOT com
Subject: Re: Exacltly when does actually DJGPP free allocated memory?
In-Reply-To: <7lfo40$jlu$1@news1.kornet.net>
Message-ID: <Pine.SUN.3.91.990704170646.13333w-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Thu, 1 Jul 1999, Seunghwan Ji wrote:

> I tried to examine if the 'malloc - free' mechanism works fine or not by
> free memory amount check:
> _go32_dpmi_remaining_physical_memory();
> _go32_dpmi_remaining_virtual_memory():
> and I could not find free memory recovery after free command executed..

This is how it should work.  The details are explained in section 15.2
of the DJGPP FAQ list.

> My question is:
> Exaclty when does actually DJGPP(or allegro) free allocated memory
> after free()?

The answer is "Never".  The memory is never returned to the OS until
the program exits, at which point ALL its memory is freed, even those
parts that your program didn't free() explicitly.  Memory you free
during the program's life goes to the list of free blocks maintained
by malloc, and is available for future allocations.

I would suggest to try first to see whether your program has some
memory leaks.  In general, if you always free all the memory that you
don't need, your program should in most cases run for many hours or
even days without exhausting the available memory, since the memory
you free() is available for reuse.

However, some patterns of memory usage, if they are left to run for
days, are known to cause fragmentation in most malloc algorithms.  If
this is your case, and if you cannot change the memory usage pattern,
you will need to use some other malloc version (GNU malloc is one
possibility).

But replacing the system malloc is not an easy task, so I would
recommend to establish the need first.  It is quite possible that some
small memory leak in your program is the cause of this problem.

- Raw text -


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