I wonder if there is a way to check how big the memory area is after malloc and realloc?
This is just to see if realloc really works as expected.
Printable View
I wonder if there is a way to check how big the memory area is after malloc and realloc?
This is just to see if realloc really works as expected.
In short no. If realloc() fails it will return NULL, else it returns a pointer to the memory, size of whatever you asked for.
Ok, thanks.:oQuote:
Originally posted by Hammer
In short no. If realloc() fails it will return NULL, else it returns a pointer to the memory, size of whatever you asked for.
>>I wonder if there is a way to check how big the memory area is after malloc and realloc?
Save the size you pass to malloc() or realloc() in a variable so you can use it later :-)
>>This is just to see if realloc really works as expected.
They return a null pointer if they fail
Code:if ((p = malloc(mem_size * sizeof(*p))) == 0)
{
/* Error */
}