D2.0 Stack allocated classes

Kyle Furlong kylefurlong at gmail.com
Fri Jun 29 23:18:04 PDT 2007


S. wrote:
> Per the memory management whitepaper, the following conditions are given for allocating a class on the stack instead of the heap.
> 
>     * are allocated as local symbols in a function
>     * are allocated using new
>     * use new with no argument
>     * have the scope storage class
> 
> That covers every way I know how to allocate a class in D.  Maybe is poorly written, and I'm confused.  Lists like this are typically used to imply that ANY of the conditions being true would cause a stack allocation.  If that's not the case, just say:
> 
> "If the class is allocated as a local symbol in a function using new with no arguments and has the scope storage class, then it is allocated on the stack."
> 
> If I'm not confused, then how do you get something to be allocated on the heap?

I had the same cognitive error reading this, I'm not sure if its 
actually ambiguous, but it did trip me up. Perhaps explicitly state that 
all conditions must be true for stack allocation?



More information about the Digitalmars-d mailing list