delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/13/20:33:22

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP equivalent of alloc.h -- coreleft()
Date: Mon, 13 Apr 1998 18:48:04 -0400
Organization: Two pounds of chaos and a pinch of salt.
Message-ID: <35329624.358@cs.com>
References: <35328CBB DOT 1044BF4A AT UTDallas DOT edu>
NNTP-Posting-Host: ppp204.cs.com
Mime-Version: 1.0
Lines: 39
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Stuart Johnston wrote:
> 
> I have a example program that uses alloc.h for the function coreleft()
> which is supposed to return the amount of free heap space.  The program
> is said to work on Borland C/C++ but when I try to compile it with
> DJGPP, it can't find alloc.h.
> 
> Is there is there an equivalent of alloc.h with coreleft() or is there
> another function that returns the amount of free heap space?

DJGPP doesn't have <alloc.h> or coreleft(); both of those are decidedly
non-standard Borland extensions.  In any case, you'll find this a
difficult task in a protected mode application, because free() does
_not_ return memory to the DPMI host/operating system; it keeps it for
reuse.  As written, malloc() is optimized for speed and not for space
efficiency or memory reporting.

If you want to know simply how much memory is available to DJGPP
programs before they allocate any for themselves, call the functions
_go32_dpmi_remaining_physical_memory() and
_go32_dpmi_remaining_virtual_memory() (declared in <dpmi.h>).  The
former tells you how much physical RAM is free; the latter tells you the
total of free physical and virtual memory.  Remember that the first time
your program frees memory, those numbers will no longer be valid, and
while they represent the actual amount of memory free, rounding by
malloc() and DPMI host restrictions can lower the amount you get in
actual usage.

The best way to track your program's memory allocation habits is to
write wrappers around malloc(), calloc(), and free() that keep records,
or use a third party debugging library that is designed for the purpose.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |     mailto:fighteer AT cs DOT com      |
| Proud owner of what might one   |   http://www.cs.com/fighteer/   |
| day be a spectacular MUD...     |       ICQ UIN#:  7406319        |
| Plan: To make Bill Gates suffer |     HEAT User ID:  Fighteer     |
---------------------------------------------------------------------

- Raw text -


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