更新时间:2023-12-01 08:08:22
不好的做法,投票从我这里。如果你的做的要分配一个值,将其设置为(无效*)0xdeadbeef。检查你的CRT可以先做虽然。一个体面的调试分配器将设置释放的内存来当它被释放后使用指针很可能引起炸弹的模式。尽管它不能保证。但后来的不的修改指针的值是更好,速度更快的解决方案。
Bad practice vote from me. If you do want to assign a value, set it to (void*)0xdeadbeef. Check what your CRT can do first though. A decent debug allocator will set freed memory to a pattern that's likely to cause a bomb when the pointer is used after it was freed. Albeit that it isn't guaranteed. But then not changing the pointer value is the better (and faster) solution.