指针的realloc问题

zkx2321 2009-10-16 02:39:17
一个char**变量,malloc了2个单位空间,并且存入了两个字符串;这时候realloc了1个空间。

问:
1、原两个空间的内容会不会被毁坏?
2、新分配的1个空间在+1方向,还是在-1方向?
...全文
76 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
和黑1 2009-10-16
  • 打赏
  • 举报
回复
学习了!
joneson118 2009-10-16
  • 打赏
  • 举报
回复
顶了!!!
MoXiaoRab 2009-10-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yuhudie203 的回复:]
realloc 再分配

1.不会破坏原来的内容
2.+1的方向
[/Quote]
补充下:连接在原来的空间的后面
yuhudie203 2009-10-16
  • 打赏
  • 举报
回复
realloc 再分配

1.不会破坏原来的内容
2.+1的方向
youyifang 2009-10-16
  • 打赏
  • 举报
回复
The realloc function changes the size of an allocated memory block.

The memblock argument points to the beginning of the memory block. If memblock is NULL, realloc behaves the same way as malloc and allocates a new block of size bytes.

If memblock is not NULL, it should be a pointer returned by a previous call to malloc, or realloc.

The size argument gives the new size of the block, in bytes. The contents of the block are unchanged up to the shorter of the new and old sizes, although the new block can be in a different location.

Because the new block can be in a new memory location, the pointer returned by realloc is not guaranteed to be the pointer passed through the memblock argument.

realloc calls malloc to use the C++ _set_new_mode function to set the new handler mode. The new handler mode indicates whether, on failure, malloc is to call the new handler routine as set by _set_new_handler.

By default, malloc does not call the new handler routine on failure to allocate memory. You can override this default behavior so that, when realloc fails to allocate memory, malloc calls the new handler routine in the same way that the new operator does when it fails for the same reason.

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧