如果将数据移动到不同的块,c ++ realloc函数是否对旧数据块应用删除操作?

Kos*_*mos 0 c++ memory-management realloc dynamic-memory-allocation

该功能可以将存储块移动到新位置,在这种情况下返回新位置.
例如,我有一个指向数组的指针:

int *arr; // somewhere next it initialized, filled with elements and etc
Run Code Online (Sandbox Code Playgroud)

在某个地方我需要:

void* location = realloc(arr, NEW_SIZE);
Run Code Online (Sandbox Code Playgroud)

旧的内存块会发生什么?

如果realloc返回不是数学的指针到arr,我应该使用下一个代码吗?:

delete arr;
arr = (int*)location;
Run Code Online (Sandbox Code Playgroud)

Lin*_*cer 7

该函数realloc继承自优秀的旧C语言.它不运行析构函数或执行任何其他C++魔术.它也只能应用于使用malloc(和朋友)分配的块- 它不能用于使用'new'分配的块.