[prev] 15 [next]

The malloc() function (cont)

malloc() function interface

void *malloc(size_t n);

What the function does:

  • attempts to reserve a block of n bytes in the heap
  • returns the address of the start of this block
  • if insufficient space left in the heap, returns NULL
Note: size_t is essentially an unsigned int
  • but has specialised interpretation of applying to memory sizes measured in bytes