- 论坛徽章:
- 1
|
请教一个动态内存分配的问题
realloc() returns a pointer to the newly allocated memory, which is
suitably aligned for any kind of variable and may be different from
ptr, or NULL if the request fails. If size was equal to 0, either NULL
or a pointer suitable to be passed to free() is returned. If realloc()
fails the original block is left untouched - it is not freed or moved.
这是man手册中的一段话,偶明显觉得它是:无法在内存块后面增大的时候(已经被别人占用了),删掉这块内存,另外开辟一块更大的内存,把这块内存中的前面部分复制过去。呵呵,具体也不太清楚。不过看man,好像多次提到了free。推测,里面也用到了free。
测试一下,如果不行。看来要看源码了。 |
|