News for hackers. Stuff that matters.
Re:Modern C++ – RAII by grues-dinner on Friday May 30, 2025 @07:46AM (#44135208)
> Stack by default - Unique ptr if needed on the heap - Shared ptr if needed to share ownership

Sounds about right. Shared ownership is fairly rare though, and you often only need shared access (reference/pointer if nullable) and can provide other, more explicit, ways of managing the lifetime.

> unique ptr is zero cost after make_unique()

Kind of, but compared to the stack, it could cause caching inefficiency because your heap-allocated thing could be almost anywhere, but your stack-allocated thing is probably in the cache already.

There are no comments on this comment yet.