allocate memory
#include <stdlib.h> /* For ANSI compatibility (malloc only) */ #include <malloc.h> /* Required for other function prototypes */ void *malloc( size_t size ); void __based(void) *_bmalloc( __segment seg, size_t size ); void __far *_fmalloc( size_t size ); void __near *_nmalloc( size_t size );
The malloc() functions allocate space for an object of size bytes. Nothing is allocated when the size argument has a value of zero.
Each function allocates memory from a particular heap, as listed below:
In a small data memory model, malloc() is equivalent to _nmalloc(); in a large data memory model, malloc() is equivalent to _fmalloc().
A pointer to the start of the allocated memory, or NULL if there isn't sufficient memory available or the requested size is zero. The _bmalloc() function returns _NULLOFF if there is insufficient memory available, or if the requested size is zero.
#include <stdlib.h> void main() { char *buffer; buffer = (char *)malloc( 80 ); if( buffer != NULL ) { /* body of program */ free( buffer ); } }
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
calloc(), _expand(), free(), halloc(), hfree(), _msize(), realloc(), sbrk()