3 ms·
Could you explain?
by marcoperaza 8y ago
Could you explain?
- Tomte 8y agoplacement new lets you choose where to construct an object. It‘s somewhat arcane, though. Few application programmers even know about it (although their C++ books all dutifully mention it, usually without more than a single sentence).
- vvanders 8y agoIt's not that arcane, we used it all the time for pooling, particle systems, in-place loading, etc. Super handy but also like most things in C++, dangerous if you don't know what you're doing.
- ebikelaw 8y agoMoreover, the outcome of a new expression isn't strongly defined. Your class may override operator new for any class-type T, and you may also override global operator new, and you may do whatever it is that you like when you do so. Same for delete.
- deleted 8y ago[deleted]
- imtringued 8y agoConstructors can fail via exceptions.
- Asooka 8y agoOne example: You can override operator new for a class to, instead of calling malloc, return from a static memory pool.