|
| malloc| Summary | |
#include <stdlib.h>
void far *malloc (
size_t size); /* block size to allocate */
or
void huge *malloc (
size_t size); /* block size to allocate */
or
void xhuge *malloc (
size_t size); /* block size to allocate */
| | Description | | The malloc function allocates a memory block from the memory pool of size bytes in length. Note - Before calling this function your program must invoke the init_mempool function to initialize the memory management routines and provides the starting address and size of the memory pool.
- Source code for this routine is provide in the LIB folder. You may modify the source to customize this function for your particular hardware environment.
- Pointer arguments and return values are far in Small, Medium, Compact, and Large Memory Models; huge in HCompact and HLarge Memory Models; and xhuge in the XLarge Memory Model. This function is not supported in the Tiny Memory Model.
| | Return Value | | The malloc function returns a pointer to the allocated block or a null pointer if there is not enough memory to satisfy the allocation request. | | See Also | | calloc, free, init_mempool, realloc | | Example | |
#include <stdlib.h>
#include <stdio.h> /* for printf */
void tst_malloc (void) {
unsigned char far *p;
p = malloc (1000); /* allocate 1000 bytes */
if (p == NULL)
printf ("Not enough memory space\n");
else
printf ("Memory allocated\n");
}
|
|
|