On Tuesday, 14 April 2015 at 08:52:19 UTC, Jacob Carlborg wrote:
On 2015-04-14 10:33, "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= <ola.fosheim.grostad+dl...@gmail.com>" wrote:

No.

"No" as in "alloca" doesn't work like that for default arguments or a string mixin is still needed?

It does work like that, but I don't see a way to pass the length to the alloca() call. Unfortunately, we can't refer to other parameters. It that were possible, it would indeed work:

import core.stdc.stdlib : alloca;
T[] stackArray(T)(size_t len, T* p = cast(T*) alloca(len * T.sizeof)) {
        return p[0 .. len];
}


If alloca() ends up within a loop you are in a bad situation. Keep in mind that alloca is released on function RETURN. Not at the scope
level. VLAs are released at scope level.

Will the string mixin by Marc prevent that problem with loops?

No, that's an inherent problem with alloca(): there's no corresponding freea().

Reply via email to