why there is no memlen();

Arunachalam G arunachalam@deeproot.co.in
Thu Oct 31 02:52:00 GMT 2002


Hi,

>
> Depends entirely on your heap manager.
>
> For example, one platform that I worked on, you could do this:
>
> typedef unsigned char byte;
> struct MemChunk {
>    unsigned long length; // 32-bit
>    byte data[1]; // stretchy buffer
> };
>
Its very tricky way to get the allocated memory length. Never knew this.
Thanks.

What is that? going 4 bytes back & reading it give the amount of memory
allocated. does it contains the attributes of the data type. and why it is
compiler specific?

I use gcc 2.95.4 on linux in IA32. The above code gave some more addtional
length than the actually allocated. (for 100 bytes it gave 105 & for 1000
it gave 1009). Is it due to alignment?

thanks,
arun.



More information about the Gcc-help mailing list