The "no gc" crowd

Daniel Davidson nospam at spam.com
Thu Oct 10 17:45:44 PDT 2013


On Friday, 11 October 2013 at 00:30:35 UTC, Simen Kjaeraas wrote:
> Here's a COW reference type that I can easily pass to a function
> requiring a mutable version of the type:
>
>   struct S {
>     immutable(int)[] arr;
>   }
>
> And usage:
>
>   void foo(S s) {}
>
>   void main() {
>     const S s;
>     foo(s);
>   }
>
>
> This compiles and works beautifully. Of course, no actual COW is
> happening here, but COW is what the type system says has to 
> happen.
> Another example COW type:
>
>   string;
>
> Now, my point here is that BigInt could easily use an immutable
> buffer internally, as long as it's purely COW. It could, and it 
> should.
> If it did, we would not be having this discussion, as bugs 
> #11148 and
> #11188 would not exist. Inventing rules like 'you should use 
> inout'
> does not help - it's obscuring the problem.
>
> TLDR: Do not use inout(T). Fix BigInt.

Good catch. immutable(T)[] is special.

Do the same with a contained associative array and you'll be my 
hero.


More information about the Digitalmars-d mailing list