Amu*_*umu 0 c c++ memory-management
假设我有一个指针*p,它指向堆上的10个内存块.现在,我用NULL(或'\ 0')手动清除它,而不是free()它,如下所示:
for (int i = 0; i < length; ++i{
p[i] = '\0';
}
Run Code Online (Sandbox Code Playgroud)
这被认为是当每个位被清零时释放的存储器块?或者,我必须使用free()来告诉操作系统内存块真正被释放并且可用(我猜)?
You do have to call free() in order to return memory to the operating system.
A memory block filled with zeroes is no more "free" than a block full of ones.
For instance, consider a bitmap consisting only of black pixels. In most formats, the associated memory block will be filled with zeroes. Does that mean that block can be reused?