Availability | All terminals |
Description | This function returns the amount of unused memory on the heap that is available to the user for allocating blocks of memory using functions like malloc() and far_malloc(). Note: This function is not the same as the CoreLeft() function. On the mentioned terminals, CoreLeft returns the amount of space on the RAM disk. |
Syntax | unsigned long Heap_CoreLeft( void ); |
Arguments | None |
Returns | The amount (in bytes) of unused memory on the heap that is available to the user for allocating blocks of memory. |
Remarks |
It is possible that malloc() or far_malloc() returns
NULL on a request for a smaller amount of memory than Heap_CoreLeft() reports.
This occurs when the reported memory does not consist out of one block, but out of several smaller
blocks. malloc() and far_malloc need a single contiguous block of memory. To determine that amount of memory left for the file system the function CoreLeft() should be used. The function CoreLeft() can also be used to determine the amount of unused memory on the heap for terminals that don't support Heap_CoreLeft(). |
Example |
#include <stdio.h> #include <stdlib.h> #include "lib.h" void main( void ) { unsigned char *block; for(;;) { while( getchar() == EOF ) Idle(); printf("\n1: mem = %lu", Heap_CoreLeft()); while( getchar() == EOF ) Idle(); block = (unsigned char *) malloc(5000L); printf("\n2: mem = %lu", Heap_CoreLeft()); while( getchar() == EOF ) Idle(); free(block); printf("\n3: mem = %lu", Heap_CoreLeft()); } } |