Mail Archives: djgpp/1999/11/03/23:20:59
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 -