3 ms·
I really do like slices, but implementing them as an (interior) pointer and a length creates some problems for GC'd languages. Is D GC'd by default? The main p
by titzer 6y ago
I really do like slices, but implementing them as an (interior) pointer and a length creates some problems for GC'd languages. Is D GC'd by default?
The main problem is that a GC needs to find the start of an object to scan it. Go originally solved this with 2-bit tags per word of memory. Now, I think they use size classes.
For Virgil, I am considering adding slices but initially implementing them as a triple of (Array, start, length), to simplify this problem. This is pretty much required for Virgil's JVM backend, but the native backend can be more efficient in the future.
Btw, can you racily write slice values and observe tearing in D?
- WalterBright 6y ago> Is D GC'd by default? It has a GC, but uses it only when operator "new" is called and a couple other cases. > can you racily write slice values and observe tearing in D? Shared data (meaning data accessible by multiple threads) is handled separately through locking library functions. Shared data types are distinct from other types.
- titzer 6y agoCan you racily write the same field containing a slice from multiple threads? Unless you have atomic multi-word writes, you could observe tearing and go out of bounds silently. One thing that JVM guarantees is that racy programs cannot break the type system. This gets hard when you have multi-word quantities.
- WalterBright 6y ago> Can you You have to use an atomic library function to do it.