Uninitialized memory blocks in VC++

前端 未结 15 1306
鱼传尺愫
鱼传尺愫 2020-12-19 08:49

As everyone knows, the Visual C++ runtime marks uninitialized or just freed memory blocks with special non-zero markers. Is there any way to disable this behavior entirely w

15条回答
  •  醉话见心
    2020-12-19 09:12

    When you create a pointer, explicity initialize it to NULL. Likewise after a delete. Depending on the value of uninitialized data (except in a few specific cases) is asking for trouble.

    You can save yourself a lot of headaches by using a smart pointer class (such as boost::shared_ptr) which will automatically deal with whether a pointer is initialized or not.

提交回复
热议问题