If you have a lot of total allocated memory, GC may still be somewhat slow (because it has to scan a lot of memory, most of which is still live). One possible approach is to do your large-scale, long-term allocations outside the GC heap (i.e., use malloc) so that the amount of GC memory that needs to be scanned is small.

One approach of reducing the amount of GC allocations that people new to D seem to overlook, is to avoid string allocations by using D's range-based algorithms instead. E.g., instead of:

        auto s = "abc" ~ myString ~ "def"; // lots of allocations
        writeln(s);

Do this instead:

        import std.range;
        auto r = chain("abc", myString, "def"); // no allocation
        writeln(r);

This isn't always possible, e.g., if you need to store the result of a concatenation and access it later, but a lot of on-the-fly allocations (i.e., short-term garbage) could be eliminated this way.


T

PERFECT !!!

Reply via email to