Allocate memory
#include <malloc.h> void* malloc( size_t size );
libc
The malloc() function allocates a buffer of size bytes.
| This function allocates memory in blocks of _amblksiz bytes (a global variable defined in <stdlib.h>). |
A pointer to the start of the allocated memory, or NULL if there's insufficient memory available.
#include <stdlib.h>
int main( void )
{
char* buffer;
buffer = (char* )malloc( 80 );
if( buffer != NULL ) {
/* do something with the buffer */
...
free( buffer );
}
return EXIT_SUCCESS;
}
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |
In QNX 4, nothing is allocated when you malloc() 0 bytes. Be careful if your code is ported between QNX 4 and QNX 6.
calloc(), free(), realloc(), sbrk()