On 24 May 2013 15:29, deadalnix <deadal...@gmail.com> wrote: > On Friday, 24 May 2013 at 05:02:33 UTC, Manu wrote: > >> On 24 May 2013 14:11, Marco Leise <marco.le...@gmx.de> wrote: >> I don't think it's hack-ish at all, that's precisely what the stack is >> there for. It would be awesome for people to use alloca in places that it >> makes sense. >> Especially in cases where the function is a leaf or leaf-stem (ie, if >> there >> is no possibility of recursion), then using the stack should be >> encouraged. >> For safety, obviously phobos should do something like: >> void[] buffer = bytes < reasonable_anticipated_buffer_**size ? >> alloca(bytes) : new void[bytes]; >> >> > That is probably something that could be handled in the optimizer in many > cases. >
The optimiser probably can't predict if the function may recurse, and as such, the amount of memory you feel is reasonable to take from the stack is hard to predict... It could possibly do so for leaf functions only, but then most of the opportunities aren't in leaf functions. I'd say a majority of phobos allocations are created when passing strings through to library/system calls.