(I read a Chinese version of the book, any translation problem plz point out.
new-handler should do:
- make more memory to be used, i.e., more likely to let the next
operator newbe successful.
- install another
new-handler, i.e., let
new-handler, i.e., pass
bad_alloc(or derived from
- no return (usually call
new_handler of class:
reuse the code above due to the same implementation for different classes:
it is limited, only adapted to memory allocated, and intermediate constructor called may throw exception.
- to check the wrong usage.
- to improve the efficiency of allocation and deallocation.
- to collect the log of usage.
- to decrease the additional space cost caused by default memory manager.
- to improve the suboptimal alignment.
- to make related objects clustered.
- to obtain non-traditional behaviors.
operator newshould have an infinite loop which tries to allocate memory.
operator deleteshould do nothing when passed by
nullptr, “Class version” should
handle the “wrong apply that requires the bigger size than the true size”.
- when write
Widget* pw = new Widget;, two functions are called, one is
operator new, one is Widget’s default construtor.
if the constructor throws, the memory allocated by the first one should be recovered, or it will be memory leak.
so the corresponding
operator deleteshould be provided correctly.
- when write a
placement operator new, plz be sure to write a
placement operator delete.
- when declaring
placement delete, plz do not hide the normal version intendedly or unconsciously.