Dynamic array ot not
Ali Çehreli
acehreli at yahoo.com
Sun Jan 16 23:03:49 UTC 2022
On 1/16/22 14:43, forkit wrote:
> Well, it's fair to say, that 'range-based programming' is kinda new
to me.
I hope it will be useful to you. :)
> 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.
That's not correct. There are many range algorithms that are lazy to
defer memory allocation but array() is not one of those. array() does
eagerly allocate memory, which is it's whole purpose:
https://dlang.org/phobos/std_array.html#array
"Allocates an array and initializes it with copies of the elements of
range r."
So, that range expression has the same allocations as your "GC
allocation" line above.
> Then I watched this, and learn about 'memory disallocation'.
>
> http://dconf.org/2015/talks/bright.html
>
> Now I understand.. I think ;-)
That applies to most other range algorithms. array() is an expensive one. :)
Ali
More information about the Digitalmars-d-learn
mailing list