5 ms·
I realize that you're mostly ranting, but on the off chance that you're serious: check out std::make_shared. It's a helper function that can allocate storage fo
by vinkelhake 9y ago
I realize that you're mostly ranting, but on the off chance that you're serious: check out std::make_shared. It's a helper function that can allocate storage for the object and shared_ptr's control block in one go. It comes with its own caveats (what doesn't in C++?), but it has the answer to your concern about allocations.
- ovao 9y agoTo add: according to cppreference, all known STL implementations leverage this optimization. This used to be specific to Microsoft's STL implementation, but apparently all the major STL vendors are now on-board with it.
- gpderetta 9y agomake_shared traces its roots back into the original boost implementation.
- rosshemsley 9y agoYep I know it :) My joke was "Oh, I should return a unique_ptr<>, but then I will be losing out on the make_shared optimization" ;)