[LCP]A question regarding malloc and how to check the size of an alloceted memory.
Kent Nyberg
blurkis at bonbon.net
Sun Feb 23 02:03:02 UTC 2003
Hello!,
This is probably a "you should already know this, now go and read a book
stupid!"-question, but i will give it a shot anyway since my book rely
do not give me the answer i need.
This is the case:
I have allocated some memory with malloc.
It is a "char *memory;" and the allocation is done as the book shows:
"memory = (char *) malloc(512000);"
Ok, the size is not from the book, but thats not important i think.
Now, i want to check the size of "memory".
Doing an "sizeof(memory)" says it is 4 bytes.
I guess that that is the size of the pointer and not the actual memory
allocated.
So, doing an sizeof(&memory) which i do recall should give me the size
of the allocated memory and not the pointer gives me also 4 bytes.
Can some one tell me why what the normal way to check the allocated size
is? And yes, malloc does not return NULL.
--
Kent Nyberg <blurkis at bonbon.net>
More information about the linuxCprogramming
mailing list