www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Stack-allocated arrays

reply Kagamin <spam here.lot> writes:
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 ... }
Nov 13 2008
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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
Nov 13 2008