This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: why there is no memlen();


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]