[Tfug] Need help with a C++ algorithm

Jude Nelson judecn at gmail.com
Fri Mar 16 15:02:31 MST 2007


On 3/15/07, Stephen Hooper <stephen.hooper at gmail.com> wrote:
>
> 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....


I see how it worked, but it only works on 32-bit systems.  I was hoping to
develop something more portable.

> 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...


Can you assume it will always work?

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.


There is no guarantee that the target allocator will work that way.  It's a
nice trick, but I was looking for something more robust.

Brian then went on to explain (very coherently) that that only works
> with dynamically allocated memory (read "malloc").
>
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>



More information about the tfug mailing list