如何在更大的存储上重新分配内容,但其余内容为零?我现在喜欢
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);
只需要自己做:
oldContent = realloc(oldContent, newBufferSize);
memset((char *)oldContent + oldBufferSize, 0, newBufferSize-oldBufferSize);