Returning dynamic array from the function

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 14 14:53:54 PDT 2014


On Saturday, 14 June 2014 at 21:37:51 UTC, Marco Cosentino wrote:
>>        int[] data = [1,2,3,4];    // create new array on the 
>> heap
>
> Thanks for the answer.
> This is the bit of information I was missing: how to create an
> array in the heap.
> Is also this a valid way to do so?
>
> int[] data = new int[0];
> data ~= [4,2,3,1];

Simply "int[] = [4,2,3,1];" will do. Arrays are always created on 
the heap by default. To override that, you can assign to a static 
array, which resides on the the stack. Then you slice your static 
array.


More information about the Digitalmars-d-learn mailing list