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

rikki cattermole rikki at cattermole.co.nz
Fri Nov 12 01:34:05 UTC 2021


I think I have summarized the main points that has been brought up in 
this thread. If I have forgotten something please add.

- ``const``/``immutable`` memory can be in read only memory, attempting 
to modify this will result in the termination of a program.
- All ``extern(D)`` classes today cannot be in read only memory due the 
monitor field.
- Both ``const`` and ``immutable`` today provide guarantees that what 
memory is pointed to is readable. But it may not be writable and 
therefore cannot be written to.
- Any escape hatch must acknowledge that memory lifetimes is not the 
same thing as the memory containing data of a given type.
- For a value reference type, with the outer type being ``const`` is 
equivalent to just the template argument type being ``const``. ``struct 
Type(const T)`` is equivalent to ``const(Type!T)`` and 
``const(Type!(const(T)))``.
- Runtime checks are required for if the metadata or data storage is null.
- Atomic operations are expensive, to lesson this the compiler should 
elide calls to reference counting methods with the help of something 
like ARC and scope.


More information about the Digitalmars-d mailing list