This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: why there is no memlen();
- From: Arunachalam G <arunachalam at deeproot dot co dot in>
- To: Eljay Love-Jensen <eljay at adobe dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 31 Oct 2002 16:00:45 +0530 (IST)
- Subject: Re: why there is no memlen();
- References: <4.3.2.7.2.20021030082146.036212e8@iplan-mn.corp.adobe.com>
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.