digitalmars.D - D2.0 Stack allocated classes
- S. (8/8) Jun 29 2007 Per the memory management whitepaper, the following conditions are given...
- Kirk McDonald (19/39) Jun 29 2007 As opposed to members of some structure or class, or as global symbols,
- Kyle Furlong (4/16) Jun 29 2007 I had the same cognitive error reading this, I'm not sure if its
- Jason House (2/3) Jun 30 2007 Where can I find that?
- davidb (4/9) Jun 30 2007 Under section "Articles" -> "Memory Management" on the left,
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?
Jun 29 2007
S. wrote:Per the memory management whitepaper, the following conditions are given for allocating a class on the stack instead of the heap.The four bullet points must all be true.* are allocated as local symbols in a functionAs opposed to members of some structure or class, or as global symbols, or the like.* are allocated using newAs opposed to e.g. returned from a function.* use new with no argumentIf a class overloads the allocator, you can pass additional arguments to new itself if the allocator accepts them, e.g.: scope Foo f = new(1, 2, 3) Foo; If you use this feature, it won't go on the stack.* have the scope storage classObviously, this is as opposed to /not/ using 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.No, this list means that ALL of the conditions must be true.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."It might be better to say "it may be allocated on the stack," or "the implementation is free to allocate it on the stack."If I'm not confused, then how do you get something to be allocated on the heap?Foo f = new Foo; // on the heap -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Jun 29 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?
Jun 29 2007
S. wrote:Per the memory management whitepaper,Where can I find that?
Jun 30 2007
Jason House schrieb:S. wrote:Under section "Articles" -> "Memory Management" on the left, http://www.digitalmars.com/d/memory.html davidPer the memory management whitepaper,Where can I find that?
Jun 30 2007