D gc on local objects

monnoroch via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 16 09:44:48 PDT 2014


I often see, that D developers say something like "remove
allocations from std lib", and it seems, that the main reason to
do it is eliminate gc calls.
What about the idea, that local objects do not use gc at all?
Maby, all temporary variables can be destroyed just like in C++,
when out of scope without stop-the-world?
Here's a silly example:

bool hasDot(string s1, string s2) {
      auto tmp = s1 + s2;
      return tmp.find(".") != -1;
}

Clearly, the tmp variable allocates, but there is no point to do
it via gc, since all memory is allocated and used in specific
scope.

What if dmd could fins those variables and swich gc allocation to
just malloc+constructor call, and destructor+free call at the end
of a scope?


More information about the Digitalmars-d mailing list