realloc64: Change reserved storage block size
Use this function to change the size of a previously reserved block of 64-bit ECB heap storage. The content of any previously reserved storage is unchanged. If the block size was increased, the content of any additional reserved storage is unknown. The reserved storage is aligned for any type of object.
Last updated
- Changed for PUT12.
- Added for PUT00.
Format
#include <tpf/tpfapi.h>
void *realloc64(void *ptr, size_t size); - ptr
- A pointer to the previously reserved ECB heap block. If this pointer is NULL, the function reserves a new block of ECB heap storage with the size, in bytes, specifed by the size parameter.
- size
- The new size, in bytes, of the storage block.
Normal return
Returns a pointer to the reallocated area of 64-bit ECB heap. The storage location of the block could have been changed by the realloc64 function, causing the returned value and the value of the ptr parameter to be different.
If the ptr parameter points to a valid 64-bit ECB heap block and the size parameter is 0, the 64-bit ECB heap block is freed and the returned value is NULL.
Error return
The following error conditions
can occur:
- The realloc64 function returns a NULL value when there is not enough storage available to expand the original block of 64-bit ECB heap to the size specified by the size parameter. The original storage block is unchanged.
- If the ptr parameter does not specify a pointer that was created previously by calloc64, malloc64, or realloc64, or if the ptr parameter points to 64-bit ECB heap that has been freed already, a system error is issued and the ECB exits.
Programming considerations
- C++ keywords
newanddeleteare not interoperable with calloc, free, malloc, realloc, calloc64, malloc64, or realloc64. - Use the free function to return the storage.
- Use the realloc64 function only for large storage requests. To request storage from the 31-bit ECB heap, use the myrealloc or realloc function.
Examples
The following example allocates
and initializes an array from the 64-bit ECB heap.
#include <stdio.h>
#include <stdlib.h>
#include <tpf/tpfapi.h>
int main(void)
{
long * array; /* start of the array */
long * index; /* index variable */
int i; /* index variable */
int num1, num2; /* number of entries in array*/
void print_array( long *ptr_array, int size);
printf( "Enter the number of elements in the array\n" );
scanf( "num1 );
/* allocate num1 entries using malloc() */
if ( (array = (long *)malloc64( num1 * sizeof( long ))) != NULL
{
for ( ptr = array, i = 0; i < num1; ++i ) /* assign values */
*ptr++ = i;
print_array( array, num1 );
printf("\n");
}
else { /* malloc error */
printf ( "Out of storage\n" );
abort();
}
/* Change the size of the array ... */
printf( "Enter the size of the new array\n" );
scanf( "num2 );
if ( (array = (long *) realloc64( array, num2* sizeof( long )))
!= NULL )
{
for ( ptr = array + num1, i = num1; i <= num2; ++i)
*ptr++ = i + 2000; /* assign values to new elements */
print_array( array, num2 );
}
else { /* realloc error */
printf( "Out of storage\n" );
abort();
}
}
void print_array( long * ptr_array, int size)
{
int i;
long * index = ptr_array;
printf( "The array of size %d is:\n", size);
for ( i = 0; i < size; ++i ) /* print array out */
printf( " array[ %i ] = %li\n", i, ptr_array[i] );
}
If the initial value entered is 2 and the second
value is 4, the following output is displayed:
Enter the size of the array The array size 2 is:
array[ 0 ] = 0
array[ 1 ] = 1
Enter the size of the new array
The array of size 4 is:
array[ 0 ] = 0
array[ 1 ] = 1
array[ 2 ] = 2002
array[ 3 ] = 2003