This question already has answers here:
How to zero out new memory after realloc
(4个答案)
6年前关闭。
如何在更大的存储上重新分配内容,但其余内容为零?
我现在喜欢
如何实现从oldContentSize到新缓冲区末尾的inde都具有值'\ 0'?
(4个答案)
6年前关闭。
如何在更大的存储上重新分配内容,但其余内容为零?
我现在喜欢
void* oldContent;
size_t oldContentSize;
size_t newBufferSize;
realloc(oldContent, newBufferSize);
如何实现从oldContentSize到新缓冲区末尾的inde都具有值'\ 0'?
最佳答案
void*newContent;
newContent = realloc(oldContent,newBufferSize);
memset(newContent + oldContentSize, 0, newBufferSize - oldContentSize);
10-07 22:30