Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 13:30:16 UTC, Simen Kjærås wrote: The short answer is 'because that's how we've chosen to define it'. A more involved answer is that changing every reference is prohibitively expensive - it would require the equivalent of a GC collection on every reallocation,

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread zack via Digitalmars-d-learn
Alright, thanks for sharing this thoughts and arguments!

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 10:17:09 UTC, zack wrote: I am new to D. Appending to an array can lead to reallocation, that's clear. But why is the "reference" b not changed accordingly to the new position and still points to "old" memory? Why is b not also changed when reallocating array

Re: Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 10:17:09 UTC, zack wrote: I am new to D. Appending to an array can lead to reallocation, that's clear. But why is the "reference" b not changed accordingly to the new position and still points to "old" memory? Why is b not also changed when reallocating array

Two "references" to dynamic array, why not change both when reallocating?

2020-11-11 Thread zack via Digitalmars-d-learn
I am new to D. Appending to an array can lead to reallocation, that's clear. But why is the "reference" b not changed accordingly to the new position and still points to "old" memory? Why is b not also changed when reallocating array a and the old data getting invalid/freed? auto a =