3 ms·
You can just provide an allocate() static method and destroy() method on your object that use placement new and call the destructor manually. Or don't and just
by pcwalton 13y ago
You can just provide an allocate() static method and destroy() method on your object that use placement new and call the destructor manually. Or don't and just use placement new/manual destructor calling yourself.
Are you trying to argue that C++ programs can't use custom allocators because of language restrictions? That's demonstrably false; Gecko and WebKit, just to name a couple of C++ codebases I'm relatively familiar with, use custom allocators everywhere.
- cmbaus 13y agoFair enough. My point was poorly made, and truthfully it has been along time since I've done significant C++ work. But it is difficult for the users of libraries like the STL to mix and match their allocation strategies, so for all practical purposes, most applications end up using the default implementation, or a single override of global new.
- coliveira 13y agoActually if you may create a policy for a particular type by implementing operator new at the class level. I think you're not well informed, because C++ is the language that gives you the most flexibility to design memory management schemes.