D - Stack memory allocation
- Vathix (8/8) Apr 12 2004 C# has a keyword stackalloc that works like new. I don't think D's auto
- J Anderson (6/12) Apr 12 2004 I think auto is good enough. If the compiler writer doesn't want auto
- Achilleas Margaritis (6/21) Apr 15 2004 It's not about performance. It is about dangling pointers: if a stack-al...
- Ben Hinkle (9/15) Apr 15 2004 see "Allocating Class Instances On The Stack" in
keyword means allocate from the stack, it only ensures scope destruction. This keyword could explicitly mean use the stack, possibly by simply using alloca(). Foo f = stackalloc Foo(bar); byte[] buf = stackalloc byte[nreserve]; -- Christopher E. Miller
Apr 12 2004
Vathix wrote:auto keyword means allocate from the stack, it only ensures scope destruction. This keyword could explicitly mean use the stack, possibly by simply using alloca(). Foo f = stackalloc Foo(bar); byte[] buf = stackalloc byte[nreserve];I think auto is good enough. If the compiler writer doesn't want auto to be on the stack for a particular piece of code (parhaps for some funky performace reasons), then so be it. -- -Anderson: http://badmama.com.au/~anderson/
Apr 12 2004
J Anderson wrote:Vathix wrote:It's not about performance. It is about dangling pointers: if a stack-allocated object pointer is passed as a parameter to some function, and the function keeps the pointer around, then upon the return of the outer function the object's memory will be de-allocated and the pointers that point to it will be dangling. By allocating everything on the heap, there is no such problem.auto keyword means allocate from the stack, it only ensures scope destruction. This keyword could explicitly mean use the stack, possibly by simply using alloca(). Foo f = stackalloc Foo(bar); byte[] buf = stackalloc byte[nreserve];I think auto is good enough. If the compiler writer doesn't want auto to be on the stack for a particular piece of code (parhaps for some funky performace reasons), then so be it.
Apr 15 2004
On Mon, 12 Apr 2004 22:00:13 -0400, Vathix <vathix dprogramming.com> wrote:keyword means allocate from the stack, it only ensures scope destruction. This keyword could explicitly mean use the stack, possibly by simply using alloca(). Foo f = stackalloc Foo(bar); byte[] buf = stackalloc byte[nreserve];see "Allocating Class Instances On The Stack" in http://www.digitalmars.com/d/memory.html be very manageable. For arrays on the stack I'd just use alloca to get a pointer and then slice it to an array the usual way: ... byte[] buf = ptr[0..nreserve];
Apr 15 2004