Houjun Liu


The heap is a self-managed area of the memory.


void *malloc(size_t size);

You should pass in the number of bytes; therefore, we need to pass in the number of bytes through something like malloc(sizeof(int)*len). The memory is not cleared out.


void *calloc(size_t nmemb, size_t size);

Put the number of elements into nmemb, and the size of them into size. Stamp zeros throughout.


Deep copy a string. strlen, malloc, strcpy, retrun.


void free(void *ptr);

Frees whatever the pointer points to. The pointer itself (a stack variable), is not deleted and still points to the freed memory.


void *realloc(void *ptr, size_t size);

Changes the memory that ptr points to to size size. If there’s not enough space, realloc moves the memory content and frees the old one.