Casting away immutability
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Sep 4 02:05:06 PDT 2015
On Friday, 4 September 2015 at 08:37:26 UTC, Kagamin wrote:
> On Thursday, 3 September 2015 at 13:28:54 UTC, Sergei Degtiarev
> wrote:
>> Agree, however, memory obtained with mmap(..., PROT_READ, ..);
>> is essentially read-only and any attempt to write to it will
>> cause immediate crash with segmentation violation. It would be
>> very desirable in this case to return something that could be
>> cast to immutable(type)[] but not type[].
>
> If you can't write to it doesn't mean it won't change. Use
> const for memory that you can't write to.
Note that you can however achieve immutability by using a
_private_ read-only mapping.
More information about the Digitalmars-d-learn
mailing list