int getmin(int a, int b)
{
return a<b?a:b;
}
void *reallocation(void *ptr, size_t size) //size_t in bytes
{
void *newptr;
int msize;
msize = getsize(ptr);
msize = getmin(msize, size);
printf("msize = %d", msize);
newptr = malloc(size);
newptr = memcpy(newptr, ptr, msize);
free(ptr);
return newptr;
}
I have implemented my own realloc, and in order to get the size of the allocated memory using malloc(however i know there isn't any method for this in c).
My reallocation function is working fine on my system How do we get the size of the memory allocated by malloc().
Also can we do inplace reallocation if the size of the previously allocated memory is greater than the new required?