Source

Branch

1/ @AbstrctMachnist

@rfleury

individual malloc/free is a common C practice and is the fair comparison; group allocations are not the norm in most programs especially in the hand-off ownership situations where unique_ptr would apply. In this light unique_ptr is strictly superior.

2/ @rfleury

@AbstrctMachnist

No, it isn’t the fair comparison, because that is not how sensible code is written.

3/ @AbstrctMachnist

@rfleury

Okay, well it’s a like-vs-like comparison. If used as a straightforward replacement, unique_ptr is better. I concede it’s not a replacement for a careful memory strategy.

4/ @rfleury

@AbstrctMachnist

But the equivalent code isn’t straightforward. It’s not careful to do something better. It’s both easier and faster. It is simply the superior way to not use them at all.

5/ @AbstrctMachnist

@rfleury

Looking at the RAD Debugger as an example (which is unfair, since you can’t look at my code), the diligence of passing an allocator through every function, and being constantly mindful of which pool a given string is coming from, does not seem simple, though it is impressive.

6/ @rfleury

It isn’t through every function, though. And it is not accurate to say you are “constantly mindful” about it. Layers which allocate plan for & control those allocations through a variety of strategies. Most allocations are bucketed into arenas, so the allocation occurs and is forgotten. Anyone who is passed an allocation can use the allocation, they do not have to care about where it came from.

7/ @AbstrctMachnist

@rfleury

Alright, but surely this is more thought than probably even 95% of programs give to such things. Nor are most programs developed with such careful attention to layers and their individual memory strategies. And I don’t think they should need to, by default.

8/ @rfleury

@AbstrctMachnist

Someone has to build those layers, is the point. The high level code doesn’t have to think about anything. I agree that at those layers, nobody should be having to think about anything other than their problem.