calloc64: Reserve and initialize heap storage
This function reserves 64-bit ECB heap storage for an array of elements and initializes the bits of each element to a value of 0. The reserved storage is aligned for any type of object.
Last updated
- Changed in 2024.
- Changed for PUT12.
- Added for PUT00.
Format
#include <tpf/tpfapi.h>
void *calloc64(size_t num, size_t size); - num
- The number of elements to be allocated.
- size
- The length, in bytes, of each element.
Normal return
Returns a pointer to the area of 64-bit ECB heap storage that was reserved.
Error return
The calloc64 function returns a NULL value if there is not enough storage available to satisfy the request.
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 calloc64 function only for large storage requests. To request storage from the 31-bit ECB heap, use the calloc or mycalloc function.
- If you specify a value of 0 for the num or size parameter, this function returns a pointer to an ECB heap buffer that is 0 bytes in size. This pointer can be passed to the free function.
Examples
The following example allocates
and initializes an array from the 64-bit ECB heap area.
#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 num; /* number of entries in array*/
printf( "Enter the number of elements in the array\n" );
scanf( "num );
/* allocate num entries */
if ( (index = array = (long *) calloc64( num, sizeof ( long )))
!= NULL )
{
for ( i = 0; i < num; ++i) /* put values in array */
*index++ = i; /* using pointer notation */
for ( i = 0; i < num; ++i ) /* print the array out */
printf( "array[ %i ] = %i\n", i, array[i] );
}
else
{ /* out of storage */
printf( "Out of storage\n" );
abort();
}
}
If the number of elements specified is 3, the
following output is displayed:
Enter the size of the array
array[ 0 ] = 0
array[ 1 ] = 1
array[ 2 ] = 2