- This wiki is out of date, use the continuation of this wiki instead
Realloc
From FenixWiki
(Difference between revisions)
Revision as of 00:28, 28 April 2007
Contents |
Definition
VOID POINTER realloc ( <VOID POINTER data> , <INT size> )
Resizes the given block of memory.
It allocates a new block of memory, copying the old data. If the new size is smaller than the old size, the last part of the data is lost.
Parameters
VOID POINTER data | - Pointer to the block of memory to be resized. |
INT size | - The size of the to be allocated memory. |
Returns
VOID POINTER : Pointer to (the first element of) the newly allocated memory block.
Errors
Insufficient memory | - There is insufficient memory available. This error doesn't occur often. |
Example
Program example; Private byte pointer pbyte; byte pointer pbyte2; int elements = 10; int newelements = 15; int i; Begin // Allocate memory pbyte = alloc(elements); // Set them to 13 memset(pbyte,13,elements); // Relocate it to a larger, newly made memory block pbyte2 = realloc(pbyte,newelements); // Set the added part's elements to 16 (newelements > elements) memset(pbyte+elements,16,newelements-elements); // Show numbers for(i=0; i<newelements; i++) say("byte2["+i+"] = " + pbyte2[i]); end Loop frame; End End