can realloc move pointer if new size smaller?

后端 未结 6 545
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 20:43

I am wondering whether the C or C++ standard guarantees that a pointer is not changed when realloc is called with a smaller (nonzero) size:

size_t n=1000;
T*         


        
6条回答
  •  自闭症患者
    2020-12-09 21:08

    On Windows, the C-Runtime grabs a heap, and then allocates memory from that heap. So the OS won't know about individual memory allocations, and thus won't move things around.

提交回复
热议问题