CARM User's Guide

Discontinued

malloc

Summary
#include <stdlib.h>

void *malloc (
  unsigned int size);   /* block size to allocate */
Description

The malloc function allocates a memory block from the memory pool of size bytes in length.

Note

  • 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.
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 *p;

  p = malloc (1000); /* allocate 1000 bytes */

  if (p == 0)
    printf ("Not enough memory space\n");
  else
    printf ("Memory allocated\n");
}