malloc: size of allocated area?

How to find the size of area allocated by malloc?? is it even possible.


for example:-

void *ptr;
ptr = malloc(10);


Here malloc should allocate 10bytes...

Can i check it in my program using 'ptr' variable, how many bytes are allocated??
Maybe using sizeof().. but how?
There is no standard way of doing this. You may be lucky and your implementation/platform has an extension to do this but otherwise the only way is to track it yourself from when the malloc() was done.

See this C language FAQ http://c-faq.com/malloc/querysize.html
Topic archived. No new replies allowed.