Encouraging memory efficiency

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 21 11:21:09 PDT 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.


More information about the Digitalmars-d mailing list