Stack-allocated arrays

Kagamin spam at here.lot
Thu Nov 13 10:46:51 PST 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 ...
}



More information about the Digitalmars-d mailing list