C++ allows overloading operator new
- both global and per-class - usual operator new
, operator new[]
used with new[]
stat
The correct answer is you cannot replace operator placement new.
§18.4.1.3 Placement forms
These functions are reserved, a C++ program may not define functions that displace the versions in the Standard C++ library.
The rationale: The only purpose of the allocation and deallocation operators is to allocate and deallocate memory, so when given memory nothing more should be done. (The standard specifically notes that these functions "Intentionally perform no other action.")
The most obvious override would be to copy this implementation.
Another sensible one would be to add some checks (for example, verifying that there is no "bound-marker" within the request zone).
I think however that the point is more than you HAVE to override it, as soon as you override the others (for a given class), because of the mechanics of name look up (or not overriding it to prevent its use, that's fine too, but it's a conscious decision).
To define your own memory management for a prereserved area is one nice use.
To have different views on the same physical data (no need to move the data) is other interseting use. It also allows you reading a structured file as chars on a buffer and then, the superimposition of the their logical structure by defining an object of that the class over the buffer. The combination of this thing with the memory mapping of files, can provide big improvements in performance. The memory mapped hardware... So, thousand applications!