[OT] Re: Why don't you advertise more your language on Quora etc ?

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 6 09:45:18 PST 2017


On Mon, Mar 06, 2017 at 05:30:56PM +0000, Rico Decho via Digitalmars-d wrote:
> > maybe that's what you're looking for:
> > https://dlang.org/phobos/core_memory.html#.GC.collect
> 
> Indeed !
> 
> I'll try to make some benchmarks with a 3D rendering loop to see how
> much time it takes if there is not much to GC.

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

-- 
If you want to solve a problem, you need to address its root cause, not just its symptoms. Otherwise it's like treating cancer with Tylenol...


More information about the Digitalmars-d mailing list