C Language Development Kit/Functions/CoreLeft
From OptiWiki
| Description | This function returns the amount of memory that is still available to the user.
On the OPH100x, this means the amount of free memory on the default drive is returned. The default drive can be set with the function set_default_drive(). It is also possible to use the function coreleft2(), that allows you to specify the drive. |
| Syntax | unsigned long coreleft(void); |
| Arguments | None |
| Returns | The amount (in bytes) of unused memory. |
| Remarks | It is possible that malloc() or far_malloc() returns
NULL on a request for a smaller amount of memory then 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. |
| Example | #include <stdio.h> #include <stdlib.h> #include "lib.h" void main( void ) { static char data[20+1]; FILE *fp; while( 1 ) { printf("\f1: mem = %lu", coreleft()); far_malloc( 70000L ); while( getchar() == EOF ) idle(); printf("\f2: mem = %lu", coreleft()); if( NULL != ( fp = fopen("TEST.DAT", "wb"))) { fwrite( data, 1, 20, fp); fclose(fp); } while( getchar() == EOF ) idle(); printf("\f3: mem = %lu", coreleft()); format(); while( getchar() == EOF ) idle(); printf("\f4: mem = %lu", coreleft()); while( getchar() == EOF ) idle(); } } |
