Dynamic array ot not

forkit forkit at gmail.com
Sun Jan 16 22:43:57 UTC 2022


On Sunday, 16 January 2022 at 11:43:40 UTC, Ali Çehreli wrote:
>
> So, in all three examples it is the same D feature, a slice, 
> that references data but the data is managed in different ways.
>
> Ali

Well, it's fair to say, that 'range-based programming' is kinda 
new to me.

With this statement:
  int[][] mArr = iota(1, 9).chunks(2).map!array.array;

- one would intuitively expect, that at the end, you end up with 
a dynamically allocated array, intialised with it's argument.

That is, you would expect some GC allocation to be going on, 
similar to what would happen with this code:

int[][] mArr2 = [[1, 2], [3, 4], [5, 6], [7, 8]]; // GC allocation

But it turns out:

int[][] mArr = iota(1, 9).chunks(2).map!array.array; // no GC 
allocation going on at all, not anywhere.

How can this be I asked myself?

Then I watched this, and learn about 'memory disallocation'.

http://dconf.org/2015/talks/bright.html

Now I understand.. I think ;-)




More information about the Digitalmars-d-learn mailing list