realloc以后,原有内存被如何处理? 回收? 释放? 不管?

如果已分配的存储块后面有空闲的空间,则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.

转载于:https://www.cnblogs.com/knightly/p/3520816.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值