简体   繁体   中英

How to determine if a buffer is freed or not

I use new to allocate a buffer, as follows:

    BYTE *p;

    p = new BYTE[20];


    ...

    delete p;

After p is deleted, if I do NOT assign NULL to p , is there a way to determine whether it has already been freed?

您无法确定这一点,这是您通常依赖于高级机制来处理内存的主要原因之一,例如智能指针( shared_ptrunique_ptr等),或者在您的情况下使用std::vector进行处理原始内存,以确保不会因未定义行为启动程序的两次delete ,忘记delete或其他令人讨厌的错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM