Reallocates a previously allocated memory block.
This function is a wrapper around the C realloc function. It changes the
size of the memory block pointed to by ptr to size bytes. The contents
of the memory block are preserved up to the minimum of the old and new sizes.
Parameters:
- ptr: A pointer to previously allocated memory (or null)
- size: The new size in bytes
Returns a pointer to the reallocated memory, which may be different from ptr,
or a null pointer if reallocation fails (in which case the original block is unchanged).
Note: If ptr is null, this behaves like malloc. If size is 0, this
may behave like free (platform-dependent).