D on next-gen consoles and for game development
Jacob Carlborg
doob at me.com
Fri May 24 04:47:31 PDT 2013
On 2013-05-24 07:02, Manu 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];
>
> toStringz is a very common source of allocations. This alloca approach
> would be great in those cases, filenames in particular.
Basically every function in Tango that operates on some kind of array
takes an array and an optional buffer (also an array). If the buffer is
too small it will allocate using the GC. If not, it won't allocate and
builds the array in place. That worked great with D1 where strings
weren't immutable.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list