Encouraging memory efficiency
Kapps via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 17 09:35:41 PDT 2014
On Thursday, 17 July 2014 at 16:28:00 UTC, 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.
In theory there would probably be an allocator that uses alloca
when Andrei's std.allocator makes it in. Using alloca is actually
rather problematic in D right now though (with DMD at least)...
https://issues.dlang.org/show_bug.cgi?id=12820
Also, there used to be a built in syntax, 'scope foo = new Foo()'
that would allocate on the stack, but that's deprecated now (and
seemed to segfault when I tried it).
More information about the Digitalmars-d
mailing list