On Saturday, 21 April 2018 at 12:08:09 UTC, Dmitry Olshansky
wrote:
On Saturday, 21 April 2018 at 07:37:50 UTC, Mike Franklin wrote:
Does D have some way to dynamically allocate on the stack?
I'm looking for something roughly equivalent to the following
C code.
int doSomething(size_t len)
{
char stackBuffer[len + 1];
doSomethingElse(stackBuffer);
}
Unbounded allocation on stack is kind of anti-pattern and a
potential DoS vector.
I'm having trouble seeing how unbounded heap allocations aren't
equally a potential DoS vector.
A separate region allocator is exactly as fast and can easily
survive across boundaries of function calls.
I guess if OP wants it on the stack it's because it doesn't need
to survive across boundaries of function calls so this buys
nothing in this case.
Also you probably want something like char[X] = void;
for efficiency if allocating on stack.
Thanks,
Mike