TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Category: Object Allocation

Synopsis:Creating and Deleting Objects


Description:
This chapter concerns the allocation and deallocation of objects using the new and delete operators.

Coding Rules

NameCheckedSynopsis
OAL#001 Only customize the memory management for a class if memory management is an unacceptably large part of the allocation and deallocation of free store objects of that class
OAL#002 If you overload operator delete, it shall be prepared to accept a null pointer
OAL#003 Checked automatically with code checker If you overload operator new for a class, you should have a corresponding operator delete
OAL#004 In case allocated memory has to be deallocated later by someone else, use a unique_ptr with move semantics
OAL#005 Checked automatically with code checker Assign a new value to a pointer that points to deallocated memory
OAL#006 Checked automatically with code checker delete shall be used only with new
OAL#007 Checked automatically with code checker Don't mix new and delete for array and non-array types
OAL#008 Checked automatically with code checker Do not use "delete" to delete raw pointers inside smart pointers
OAL#009 Checked automatically with code checker Do not overload the global operator new or the global operator delete
OAL#010 Checked automatically with code checker Do not overload the new and/or delete operators
OAL#011 Checked automatically with code checker Use smart pointers for memory management
OAL#012 Checked automatically with code checker Don't use auto_ptr, use unique_ptr instead
OAL#013 Checked automatically with code checker Use std::make_shared instead of constructing a shared_ptr from a raw pointer
OAL#015 Checked automatically with code checker Use nullptr instead of 0 or NULL for pointers
OAL#017 Checked automatically with code checker Use smart pointers from the standard library
OAL#018 Checked automatically with code checker Don't forget to give scoped locks a name