malloc,分配指定字节的存储区,未进行初始化
calloc,为指定长度的对象分配存储空间,每一bit初始化为0
realloc,增加或减少之前分配的长度,新增区域未进行初始化
man手册说明:
The malloc() function allocates size bytes of memory and returns a pointer to the allocated memory. The calloc() function contiguously allocates enough space for count objects that are size bytes of memory each and returns a pointer to the allocated memory. The allocated memory is filled with bytes of value zero The realloc() function tries to change the size of the allocation pointed to by ptr to size, and returns ptr. If there is not enough room to enlarge the memory allocation pointed to by ptr, realloc() creates a new allocation, copies as much of the old data pointed to by ptr as will fit to the new allocation, frees the old allocation, and returns a pointer to the allocated memory. If ptr is NULL, realloc() is identical to a call to malloc() for size bytes. If size is zero and ptr is not NULL, a new, minimum sized object is allocated and the original object is freed. When extending a region allocated with calloc(3), realloc(3) does not guaran- tee that the additional memory is also zero-filled. The free() function deallocates the memory allocation pointed to by ptr. If ptr is a NULL pointer, no operation is performed.realloc 参数size为期望的ptr指向空间的大小,当size大于ptr原有长度,可能会导致重新开辟完整空间,更改ptr的地址
泄漏:调用alloc类函数后,最终未调用free释放空间。对同一空间调用两次free
本内容为个人学习内容,如有不正请指正,与诸君共勉 学习unp第一天