Houjun Liu

heap

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

malloc

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.

calloc

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.

strdup

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

free

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.

realloc

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.