free (Windows CE 5.0)
Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference
Deallocates or frees a memory block.
void free( void*memblock);
Parameters
- memblock
Previously allocated memory block to be freed.
Return Values
None.
Remarks
The free function deallocates a memory block, memblock, that was previously allocated by a call to malloc, or reallocated by a call to realloc.
The number of freed bytes is equivalent to the number of bytes requested when the block was allocated or reallocated.
If memblock is NULL, the pointer is ignored and free immediately returns. Attempting to free an invalid pointer , that is, a pointer to a memory block that was not allocated by malloc or realloc, can affect subsequent allocation requests and cause errors.
Example
/* MALLOC.C: This program allocates memory with
* malloc, then frees the memory with free.
*/
#include <stdlib.h> /* For _MAX_PATH definition */
#include <stdio.h>
#include <malloc.h>
void main( void )
{
char *string;
/* Allocate space for a path name */
string = malloc( _MAX_PATH );
if( string == NULL )
printf( "Insufficient memory available\n" );
else
{
printf( "Memory space allocated for path name\n" );
free( string );
printf( "Memory freed\n" );
}
}
Output
Memory space allocated for path name
Memory freed
Requirements
OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.
See Also
Send Feedback on this topic to the authors