The two main characters in this article are the assignment routines and the return routines (allocation and deallocation routines, which is operator new and operator delete), and the supporting role is New_handler, which is when operator The function called when new does not meet the client's memory requirements.
The heap memory used by the STL container is managed by the allocator object owned by the container (allocator objects), not directly managed by new and delete.
Article 49: Understand New-handler's behavior (understand the behavior of the New-handler.)
Please remember:
1) Set_new_handler allows the client to specify a function that is called when the memory allocation is not met.
2) Nothrow New is a fairly limited tool because it only applies to memory allocations, and subsequent constructor calls may throw exceptions.
Article 50: Understanding the appropriate replacement time for new and delete (Understand when it makes sense to repace new and delete.)
Keep in mind that there are many reasons to write custom new and delete, including improving performance, debugging heap errors, and collecting heap usage information.
Article 51: To write new and delete when you need to adhere to the general (adhere to Convention when writing new and delete.)
Please remember:
1) operator new should contain an infinite loop in which to attempt to allocate memory, and if it fails to meet memory requirements, the call is New-handler. It should also be able to handle 0 bytes applications. The class-specific version should also handle "larger (error) applications than the correct size."
2) Operater Delete should not do anything when a null pointer is received. The class-specific version should also handle "larger (error) applications than the correct size."
clause 52: Write placement new also to write placement delete (Write placement Delete if you Write placement new.)
Please remember:
1) When you write a placement operator new, make sure that the corresponding placement operator delete is also written. If you do not do this, your program may be exposed to a memory leak that is slightly intermittent.
2) When you declare placement new and placement Delete, make sure that you do not inadvertently obscure their normal version.
[Effective C + +] customizing new and delete