Encouraging memory efficiency

Tero via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 17 09:27:59 PDT 2014


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.


More information about the Digitalmars-d mailing list