Would you pay for GC?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Jan 25 11:47:26 UTC 2022

On Tuesday, 25 January 2022 at 10:56:50 UTC, Paulo Pinto wrote:
> Pity that programmer knowledge can't do much to ABI 
> requirements.

C++ has an ABI?

> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1116r0.pdf

So this is basically about giving a shared_ptr the semantics of a 

That is not required for what we are talking about here.

> Also that trick only works in single developer code bases, good 
> luck not introducing a memory corruption some months/years down 
> the line.

No, this is not a big issue if you create proper ADTs. The issue 
is that it is very difficult for a compiler to distinguish 
between objects that "wrap ownership" around a data-structure and 
nodes within a datastructure; in particular what happens to 
ownership when those nodes are rearranged.

However, the programmer should have good and solid knowledge 
about this, so you only need to increment on the root-object if 
you know that nodes do not escape below a point in the call tree. 
(And you might be able to wrap this in a reference-type specific 
to the ADT).

Anyway, in C++ you tend almost always to use unique_ptr, 
shared_ptr is the exception.  So you usually have very few 
shared_ptrs and therefore they are not all that hard to reason 

For a language like D you could have ARC + borrow checker + the 
ability to constrain ARC-pointers (to get a unique_ptr) for 
shared objects and something GC-like for objects local to 

More information about the Digitalmars-d mailing list