[Tfug] Need help with a C++ algorithm

Stephen Hooper stephen.hooper at gmail.com
Thu Mar 15 11:39:04 MST 2007


On 3/15/07, Jude Nelson <judecn at gmail.com> wrote:
> Thanks for all the replies!

Which you obviously didn't really think about, though I still would
have written you a C program simply because I enjoy doing so....

> You're sure glibc's allocator doesn't have a method for
> determining the size of an allocated block, given a pointer to it?  I would
> be very surprised if it didn't, because then how would free() work?
>

If you read my email above I just explained how free worked...  the
integer below the base pointer is the allocated size of the block...

To restate the blindingly obvious "C" code, free does something like
this: "pointer - sizeof(size_t)" to find how much data was allocated
by the malloc.

Brian then went on to explain (very coherently) that that only works
with dynamically allocated memory (read "malloc").




More information about the tfug mailing list