On 07/12/2016 02:45 PM, Jacob Carlborg wrote:
On 2016-07-12 07:33, Andrei Alexandrescu wrote:
The solution (very ingenious, due to dicebot) in fact does not quite
cast immutability away. Starting from a possibly immutable pointer, it
subtracts an offset from it. At that point the memory is not tracked by
the type system, but known to the allocator to contain metadata
associated with the pointer that had been allocated with it. After the
subtraction, the cast exposes the data which is mutable without
violating the immutability of the object proper. As I said, it's quite
an ingenious solution.
What if the immutable data is stored in ROM [1]? I assume it's not
possible to have an offset to a completely different memory storage.
Not sure if this is important enough to care about.
[1] http://dlang.org/const-faq.html#invariant
The assumption is that the memory comes from that allocator. -- Andrei