www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/03/23:20:59

Date: Wed, 3 Nov 1999 09:55:14 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Steve <stephenc AT rmel DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Standard Library
In-Reply-To: <941558204.23499.0.nnrp-08.d4e443d2@news.demon.co.uk>
Message-ID: <Pine.SUN.3.91.991103095456.29562F-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 Tue, 2 Nov 1999, Steve wrote:

> Firstly, how do you make use of the size information within 'malloc' and
> 'free', when this is held locally and other functions do not has scope
> access to these variables.

That's not what I meant.  What I meant is that `malloc' stores the
info immediately preceding and following the buffer whose pointer it
hands back to you.  By accessing these hidden fields of the buffer
returned by `malloc', you can get at the info.

For example, the following code snippet reconstructs the BLOCK
structure which holds the information about the allocated buffer:

  char *ptr = malloc (1000);
  ...
  BLOCK *block = (BLOCK *)(ptr - 4);

Now you can, for example, get the block size like this:

  size_t block_size = block->size;

As I said, reading the source of malloc in djlsr202.zip will show you
this and other details of the info stored by malloc in the buffer that
it returns.

> Secondly, where can I find the source and binaries for the heap debugging
> libraries  that you mentioned

They are on the usual DJGPP sites on SimTel.NET mirrors, in the v2tk
directory.

- Raw text -


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