2 ms·
I'm over-generalising, but: if you want performance, don't create a huge soup of tiny objects on the heap pointing to each other as can often be seen in 'smart-
by flohofwoe 10y ago
I'm over-generalising, but: if you want performance, don't create a huge soup of tiny objects on the heap pointing to each other as can often be seen in 'smart-pointer-heavy' C++ projects. Creating and destroying objects on the heap is expensive, and you'll end up pointer-chasing with cache-misses all over place.
Unfortunately smart-pointers are only useful with this 'every object lives isolated on the heap' approach, since alloc-init and cleanup-free are merged into the same operation. Of course there's ways around that by writing custom allocators, but this just adds more complexity when often granular objects with their own lifetime and ownership aren't needed in the first place.
Smart-pointers are a convenience feature to not having to think about object-lifetime, and in the case of shared-pointers, also to not think about ownership, they're not about performance. If you want performance, don't allocate single objects on the heap, and spend some time thinking about data layout in memory.