cloning array

Basile.B b2.temp at gmx.com
Wed Jun 2 16:07:35 UTC 2021


On Wednesday, 2 June 2021 at 15:59:38 UTC, Basile.B wrote:
> On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote:
> works as you expect

On Wednesday, 2 June 2021 at 15:59:38 UTC, Basile.B wrote:

```d
import std;

void main() {

     auto a = new double[][] (0,0);
     a ~= [ 1.0, 2.45];
     a ~= [ 4.9 ,28, 9];



     auto b = [a[0].dup, a[1].dup];

     a[1] = remove(a[1],1);

     writeln(b);
}
```

works a expected. The reason why is that your array elements are 
fat pointers, so when you dup a, you dup some fats pointer, so 
you got the same elements as "a" but accessible from another 
chunck of memory.


More information about the Digitalmars-d-learn mailing list