November 18, 2012
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?
November 18, 2012
Namespace:

> Code: http://dpaste.dzfl.pl/6ae9f91a

I 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
November 18, 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.
November 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
November 18, 2012
On 18.11.2012 16:21, bearophile wrote:
> 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

I just took a look. It's in my mailbox but does not show up in the web interface.
November 18, 2012
Ok, understood.
I hoped that I could create a better interface.
November 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.


November 18, 2012
On Sunday, 18 November 2012 at 16:01:10 UTC, Tobias Pankrath wrote:
> 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.

The best would be if my code would work.
I wish some syntax like:
int len = 42;
int[len] arr = stackalloc!(int)(len);
Top | Discussion index | About this forum | D home