November 13, 2008
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 ...
}
November 13, 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