/* free example */ #include <stdlib.h> /* malloc, calloc, realloc, free */ int main () { int * buffer1, * buffer2, * buffer3; buffer1 = (int*) malloc (100*sizeof(int)); buffer2 = (int*) calloc (100,sizeof(int)); buffer3 = (int*) realloc (buffer2,500*sizeof(int)); free (buffer1); free (buffer3); return 0; } |
calloc | 分配并且以零初始化数组(function) |
malloc | 分配内存块(function) |
realloc | 重新分配内存块(function) |