On Sunday, 16 January 2022 at 23:03:49 UTC, Ali Çehreli wrote:

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.


Honestly, that is what I thought, and expected.

However, when I compiled with: -profile=gc .. it indicated no GC allocation going on. That's really why I got confused - because, as you say, the array statement (as I understand it)will result in a dynamically allocated array (i.e. allocated on GC heap).

But -profile=gc .. says no. It's not.

int[][] mArr = [[1, 2], [3, 4], [5, 6], [7, 8]]; // GC allocation occurs. int[][] mArr = iota(1, 9).chunks(2).map!array.array; // No GC allocation occurs.

  • 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