Hacker News new | ask | show | jobs
by nly 282 days 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

1 comments

Perhaps rather than "a tonne of options" people might like to have fewer that are actually good ?
I'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.

I 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.