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

  • Dynamic array ot not forkit via Digitalmars-d-learn
    • Re: Dynamic array ot not Ali Çehreli via Digitalmars-d-learn
      • Re: Dynamic array ot... forkit via Digitalmars-d-learn
        • Re: Dynamic arra... Ali Çehreli via Digitalmars-d-learn
          • Re: Dynamic ... Salih Dincer via Digitalmars-d-learn
            • Re: Dyn... Ali Çehreli via Digitalmars-d-learn
              • Re:... H. S. Teoh via Digitalmars-d-learn
              • Re:... Ali Çehreli via Digitalmars-d-learn
          • Re: Dynamic ... forkit via Digitalmars-d-learn
            • Re: Dyn... Ali Çehreli via Digitalmars-d-learn
              • Re:... forkit via Digitalmars-d-learn
                • ... Ali Çehreli via Digitalmars-d-learn
                • ... forkit via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... forkit via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... forkit via Digitalmars-d-learn
                • ... Salih Dincer via Digitalmars-d-learn
                • ... Salih Dincer via Digitalmars-d-learn

Reply via email to