TempAlloc review starts now

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Jun 5 16:26:27 PDT 2011


On 06/05/2011 06:22 PM, bearophile wrote:
> Andrej Mitrovic:
>
>> I wish "newVoid" was a language feature. If we have:
>> int x = void;
>>
>> It'd also be nice to have a similar form for the new operator:
>> int[] x = void new int[](size);
>> x[] = 1;
>>
>> "int x = void" might not save too much cycles, but initializing a
>> large array twice.. that's another thing.
>>
>> newVoid seems to only work for 1-dimensional arrays. I could use
>> something of this form:
>> double[][] arr = newVoid!(double[][])(16, 100);
>>
>> Not a big deal, I could write something like this for my own projects.
>> I'm just commenting.
>>
>> I used GC.malloc before but I never once thought about setting the
>> NO_SCAN flag. Heh. :)
>
> This is kind of off-topic.
> There is a very simple syntax, nice and clean:
>
> // doesn't initialize foo1
> auto foo1 = new uint[5] = void;

Everywhere else in the language, expr1 = expr2 = expr3 means "expr2 gets 
expr3 and then exp1 gets expr2). Cue the slave choir in Nabucodonosor, 
adagio sostenuto, piano ma espressivo: "Special cases are baaaaad... 
special cases are veeery baaaaad...."

new T[size](void) and new T[size](initializer) have been discussed, 
Walter never got around to thinking of implementing them.


Andrei


More information about the Digitalmars-d mailing list