C ++ Memory Problems record

C ++ memory problems that may come up roughly there are so few ways:

  1. Buffer overflow (buffer overrun).

    Use vector / String buffer to manage automatically the length of a buffer in mind, and modify the buffer member functions, rather than a raw pointer.

  2. Dangling pointers, wild pointers.

    用shared_ptr/weak_ptr

  3. Repeat release (delete twice).

    With scoped_ptr, released only once when the object destruction.

  4. Memory leaks (memory leak).

    With scoped_ptr, the object is automatically released when the destructor.

  5. Unpaired new delete.

    Try to avoid their own new, using the vector.

  6. Memory chips (memory fragmentation).

Guess you like

Origin www.cnblogs.com/whutao/p/10947738.html