digitalmars.D.learn - Stack allocated arrays
- Namespace (5/5) Nov 17 2012 Code: http://dpaste.dzfl.pl/6ae9f91a
- bearophile (14/15) Nov 17 2012 I think you can't use alloca() lie this, buf vanishes when the
- Tobias Pankrath (3/8) Nov 18 2012 Maybe the array is allocated in the frame of the constructor
- bearophile (5/7) Nov 18 2012 That's probably right, you can't use alloca that way (It seems my
- Tobias Pankrath (3/10) Nov 18 2012 I just took a look. It's in my mailbox but does not show up in the web
- Namespace (2/2) Nov 18 2012 Ok, understood.
- Tobias Pankrath (3/5) Nov 18 2012 I think a good interface would be a generic array class/struct that can
- Namespace (6/11) Nov 18 2012 The best would be if my code would work.
Code: http://dpaste.dzfl.pl/6ae9f91a Can someone explain me these results (switch the version statement from 'none' to 'all' in 'reserve')? Is it possible that I blown the stack frame? If so: why and can my code/idea work?
Nov 17 2012
Namespace:Code: http://dpaste.dzfl.pl/6ae9f91aI think you can't use alloca() lie this, buf vanishes when the constructor ends: this(const size_t len)(ref T[len] arr) { this._buf = cast(T*) alloca(len * T.sizeof); for (size_t i = 0; i < len; ++i) { this._buf[i] = arr[i]; } this._length = len; } Bye, bearophile
Nov 17 2012
On Sunday, 18 November 2012 at 01:55:48 UTC, Namespace wrote:Code: http://dpaste.dzfl.pl/6ae9f91a Can someone explain me these results (switch the version statement from 'none' to 'all' in 'reserve')? Is it possible that I blown the stack frame? If so: why and can my code/idea work?Maybe the array is allocated in the frame of the constructor which is lost afterwards.
Nov 18 2012
Tobias Pankrath:Maybe the array is allocated in the frame of the constructor which is lost afterwards.That's probably right, you can't use alloca that way (It seems my answer yesterday got lost). Bye, bearophile
Nov 18 2012
On 18.11.2012 16:21, bearophile wrote:Tobias Pankrath:I just took a look. It's in my mailbox but does not show up in the web interface.Maybe the array is allocated in the frame of the constructor which is lost afterwards.That's probably right, you can't use alloca that way (It seems my answer yesterday got lost). Bye, bearophile
Nov 18 2012
Ok, understood. I hoped that I could create a better interface.
Nov 18 2012
On 18.11.2012 16:46, Namespace wrote:Ok, understood. I hoped that I could create a better interface.I think a good interface would be a generic array class/struct that can be parameterized to use a stack allocator.
Nov 18 2012
On Sunday, 18 November 2012 at 16:01:10 UTC, Tobias Pankrath wrote:On 18.11.2012 16:46, Namespace wrote:The best would be if my code would work. I wish some syntax like: int len = 42; int[len] arr = stackalloc!(int)(len);Ok, understood. I hoped that I could create a better interface.I think a good interface would be a generic array class/struct that can be parameterized to use a stack allocator.
Nov 18 2012