 |
realloc |
Function* (tigcc.a) |
Reallocates allocated memory.
realloc attempts to shrink or expand the previously allocated block to NewSize
bytes. The Ptr argument points to a memory block previously obtained by calling
malloc, calloc, or realloc.
It may also be NULL; in this case the function simply calls malloc.
realloc adjusts the size of the allocated block to NewSize, copying the contents to a new location
if necessary (note that the block will not stay in high memory after the reallocation, but
it will still remain locked; see other functions from this header file for more info).
realloc returns the address of the reallocated block, which can be different than the address
of the original block. If the block cannot be reallocated, realloc returns NULL.
Usually realloc keeps the current contents of the block intact; only the portion of the block
which is newly allocated is not initialized and contains random content. However, unlike
HeapRealloc, the function frees the block pointed to by
Ptr if there was an error, so you can not assume that the data pointed to by Ptr
is still valid. This is done because there is no way to guarantee that Ptr is still
valid after the heap compression which HeapRealloc tries to
perform (this function uses HeapRealloc internally).
Note: realloc is introduced to increase compatibility with ANSI C. It is better to use
the official TIOS function HeapRealloc, which uses a system of handles
to memory blocks.
Uses: HeapAllocPtr, HeapFree, HeapRealloc, HeapUnlock, HLock
Used by: realloc_throw, atexit
See also: malloc, calloc, free, realloc_throw