如果已分配的存储块后面有空闲的空间,则realloc不会移动数据而只是增加原来存储块的长度,并返回传给它的原存储块的指针。
但当前存储块后面没有足够的空闲空间时,realloc会重新分配一存储块,并移动当前存储块的内容到新块,然后返回新块的指针。
realloc() changes the size of the memory block pointed to by ptr to
size bytes. The contents will be unchanged to the minimum of the old
and new sizes; newly allocated memory will be uninitialized. If ptr is
NULL, the call is equivalent to malloc(size); if size is equal to zero,
the call is equivalent to free(ptr). Unless ptr is NULL, it must have
been returned by an earlier call to malloc(), calloc() or realloc().
If the area pointed to was moved, a free(ptr) is done.