GC in D and synadard library.
rikki cattermole
rikki at cattermole.co.nz
Thu Dec 21 11:00:36 UTC 2017
On 21/12/2017 10:49 AM, Dan Partelly wrote:
>
> I started to look into D very recently. I would like to know the
> following, if you guys are so nice to help me:
>
> 1. What is the performance of D's GC, what trade-offs where done in
> design , and if a in-deep primer on efficient usage and gotchas of the
> current implementation exists.
>
> 2. GC is never good enough. What are the current plans in this area for
> D. In general, please point me to the place where current work on D is
> done.
Ref counting isn't perfect but it is good enough. Scope attribute still
needs more work but again may work in some cases.
> 3. I need to be able to run with GC totally disabled sometimes. In the
> light of this:
https://dlang.org/phobos/core_memory.html#.GC.disable
import core.memory : GC;
GC.disable;
That will disable the GC to attempt to collect (you can ask it to later
on or renewable at your pleasure).
But bare in mind, the GC will only ever try to collect when you allocate
memory.
> - are there any features of core language which depend on garbage
> collection ? (i.e unbound arrays, strings ..)
Yes, lambdas, new, .length changing and that includes ~=.
> - are there any features from standard library which depend on
> active garbage collection?
Available lots.
Enabled, I highly doubt that part.
Just remember, you can quite easily call into C and allocate memory the
hard way of malloc.
int[] data = (cast(int*)malloc(int.sizeof * 8))[0 .. 8];
free(data.ptr);
Of course, preallocating and using buffers is always the best approach,
doesn't matter if it was allocated by the GC or not.
More information about the Digitalmars-d-learn
mailing list