Memory Allocation

  1. malloc - Allocates a single block of memory. Initialized to garbage values. Returns a pointer to the first byte of the allocated memory that can be casted into any type.
ptr = (cast-type*) malloc(byte-size)
  1. calloc - Allocates memory in the heap and initializes the memory to zero.
ptr = (cast-type*) calloc(n, element-size);
  1. free - Deallocates memory.
free(ptr);
  1. realloc - Reallocates memory, and the old content will be copied to the new memory area.
ptr = realloc(ptr, newSize);
Yiming Zhang
Yiming Zhang
Quantitative Researcher Associate, JP Morgan