Stack-allocated arrays
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Nov 13 11:44:47 PST 2008
Kagamin wrote:
> Andrei Alexandrescu Wrote:
>
>> With the SuperStack in place, code could look like this:
>>
>> void foo(in size_t s)
>> {
>> auto a = SuperStack.array(int)(s, Uninitialized.yeahIKnow);
>> scope(exit) SuperStack.free(s);
>> ... play with a ...
>> }
>
> void foo(in size_t s)
> {
> StackFrame m; //struct, remember heap status in constructor
> //restore in destructor
> //bonus: can't alloc unless StackFrame is created
> auto a = m.alloc(int[])(s, Uninitialized.yeahIKnow);
> //scope(exit) SuperStack.free(s); you don't need free to free stack
> ... play with a ...
> }
Sweet!!
Andrei
More information about the Digitalmars-d
mailing list