July 21, 2014
On 19/07/2014 01:31, Timon Gehr wrote:
> auto createBuffer(T,alias size)(T[]
> buf=(cast(T*)alloca(size))[0..size]){ return buf; }

alloca(T.sizeof * size)
July 21, 2014
On 7/17/2014 9:27 AM, Tero wrote:
> Just watched Don's DConf 2014 talk where he said D has to be ruthless about
> memory inefficiency. Here's one thing that I think could help avoid unnecessary
> garbage: built-in syntax for this:
>
> import core.stdc.stdlib : alloca;
> ubyte[] buffer = (cast(ubyte*) alloca(bufsize)) [0 .. bufsize];
>
> Often bufsize is not known at compile-time but it won't change after the buffer
> allocation. So there's no reason to create garbage other than the *inconvenience*
> of using alloca. Allocating in the stack seems ideal so I'd encourage that by a
> clean syntax. I keep missing this feature.

You might be interested in std.internal.scopebuffer.
1 2
Next ›   Last »