Challenge: write a reference counted slice that works as much as possible like a built-in slice

deadalnix deadalnix at gmail.com
Wed Nov 10 13:42:42 UTC 2021


On Tuesday, 9 November 2021 at 15:37:13 UTC, Atila Neves wrote:
> The main point of vector is that one can append to it without 
> using the GC. I guess that "this thing has a length only known 
> at runtime that won't change and doesn't use the GC" is useful 
> too, but not nearly as much as being able to append.

Pedantic note, but as far as I can tell, this is a point that is 
often missed when discussing D: What you want isn't to avoid the 
GC, it is to avoid leaking.

You absolutely categorically want to allocate using the GC. If 
you don't, then you can't store anything that is managed by the 
GC within the vector, or you risk seeing it collected by the GC 
while it is still live.

What you do not want is to leak. Because leaking is what 
eventually leads to a GC cycle, which is actually what you want 
to avoid.


More information about the Digitalmars-d mailing list