4 ms·
Efficient memory allocation is part of a well written designed API. Languages like C++ give you a tonne of options here, from passing in scratch buffers to lib
by nly 1y ago
Efficient memory allocation is part of a well written designed API.
Languages like C++ give you a tonne of options here, from passing in scratch buffers to libraries, passing in reusable containers, move semantics, to type erased primitives like std::memory_resource and std::shared_ptr
- tialaramex 1y agoPerhaps rather than "a tonne of options" people might like to have fewer that are actually good ?
- nly 1y agoI'd you're using an unmanaged language then you need to think about memory allocation and ownership. This is something you should think about early on in your design.
- tialaramex 1y agoI do think about such things, but having "a tonne of options" when they're mostly terrible is the opposite of helpful. Let's pull out an easy one, you mention the move assignment semantic. In C++ that's a performance leak because it isn't the destructive move - so each such move incurs a creation whether you wanted one or not and it may also incur a "moved-from" check in the destructor, another overhead you wouldn't pay with the destructive move.