array construction without heap alloc

Frank Benoit keinfarbton at googlemail.com
Sat Dec 22 07:19:26 PST 2007


Jarrett Billingsley schrieb:
> "Frank Benoit" <keinfarbton at googlemail.com> wrote in message 
> news:fkj3oe$2qcm$1 at digitalmars.com...
> 
>> I wonder why arrayliterals are allocated on the heap.
> 
> Probably to prevent otherwise very common errors like:
> 
> void foo(int x, int y)
> {
>     someGlobal = [x, y];
> }
> 
> int[] bar(int x, int y)
> {
>     return [x, y];
> }
> 
> i.e. escaping references to a locally-allocated array.
> 

So it is exaclty the same situation how it is with pointers to local
function in D1 compared to D2.

In D1 you need to know what to do, in D2 there is no way around the heap.


More information about the Digitalmars-d-learn mailing list