www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D garbage collector and real-time systems

reply "Tom" <tom.k.cook gmail.com> writes:
What's the state of deterministic GC in D, or alternatively being
able to disable the GC?

I've been looking into languages to implement a real-time testing
system and had thought of D, but AFAICT the GC makes it
unsuitable.  The CGCD effort looks to be moving in the right
direction, but it would still be stop-the-world, just not for as
long as it used to.

Something like Lua's iterative GC would be better, as I think it
would give deterministic real-time latency alongside the GC (by
making the GC interruptible).  Are there any plans in this
direction?

Or is there now the possibility of disabling the GC altogether,
or replacing it with a refcounting 'GC' etc?
Jan 27 2015
next sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Wed, 28 Jan 2015 06:58:41 +0000, Tom wrote:

 Or is there now the possibility of disabling the GC altogether, or
 replacing it with a refcounting 'GC' etc?
you still can do manual memory management with `malloc()` and friends.=20 but you must be very cautious with dynamic arrays and slices. may be your=20 best bet is to not use built-in dynamic arrays at all and write a=20 replacement class with manual memory management. ah, and the same for AAs. it's possible, if somewhat cumbersome. and you can use 'dmd -vgc' to=20 check for hidden allocations. so it may be not as simple as adding some=20 compiler switch, but still not that hard too.=
Jan 27 2015
next sibling parent "Nicholas Wilson" <iamthewilsonator hotmail.com> writes:
On Wednesday, 28 January 2015 at 07:43:35 UTC, ketmar wrote:
 On Wed, 28 Jan 2015 06:58:41 +0000, Tom wrote:

 Or is there now the possibility of disabling the GC 
 altogether, or
 replacing it with a refcounting 'GC' etc?
you still can do manual memory management with `malloc()` and friends. but you must be very cautious with dynamic arrays and slices. may be your best bet is to not use built-in dynamic arrays at all and write a replacement class with manual memory management. ah, and the same for AAs.
There is also bitbucket.org/infognition/dstuff for some other gc related hacks that may be of use.
Jan 28 2015
prev sibling parent Yuxuan Shui <yshuiv7 gmail.com> writes:
On Wednesday, 28 January 2015 at 07:43:35 UTC, ketmar wrote:
 On Wed, 28 Jan 2015 06:58:41 +0000, Tom wrote:

 Or is there now the possibility of disabling the GC 
 altogether, or replacing it with a refcounting 'GC' etc?
you still can do manual memory management with `malloc()` and friends. but you must be very cautious with dynamic arrays and slices. may be your best bet is to not use built-in dynamic arrays at all and write a replacement class with manual memory management. ah, and the same for AAs. it's possible, if somewhat cumbersome. and you can use 'dmd -vgc' to check for hidden allocations. so it may be not as simple as adding some compiler switch, but still not that hard too.
For manually managed arrays, containers, I would recommend the emsicontainers (https://github.com/economicmodeling/containers)
Oct 28 2016
prev sibling next sibling parent "Kagamin" <spam here.lot> writes:

Some people including myself write D with only minimal runtime 
(bare metal profile). Is it what you're looking for?
Jan 27 2015
prev sibling parent reply "Mike" <none none.com> writes:
On Wednesday, 28 January 2015 at 06:58:42 UTC, Tom wrote:
 Or is there now the possibility of disabling the GC altogether,
 or replacing it with a refcounting 'GC' etc?
You can disable the GC: There is a RefCounted struct in the standard library: But, last I heard there were some problems with it: http://forum.dlang.org/post/cakobtxrmvrpqhswmfsy forum.dlang.org I suggest reading this article: http://wiki.dlang.org/Memory_Management. It provides more information and working examples illustrating some techniques for avoiding the garbage collector. Note that D has 3 built-in types: exceptions, dynamic arrays, and associative arrays, that may be difficult to use without the GC: http://dlang.org/builtin.html. Mike
Jan 28 2015
next sibling parent reply Martin Nowak <code+news.digitalmars dawg.eu> writes:
On 01/28/2015 09:12 AM, Mike wrote:
 Note that D has 3 built-in types: exceptions, dynamic arrays, and
 associative arrays, that may be difficult to use without the GC:
 http://dlang.org/builtin.html.
4 actually, if you count delegate closures. http://dlang.org/function.html#closures
Jan 30 2015
parent reply Tom <tom.k.cook gmail.com> writes:
On Friday, 30 January 2015 at 11:54:54 UTC, Martin Nowak wrote:
 On 01/28/2015 09:12 AM, Mike wrote:
 Note that D has 3 built-in types: exceptions, dynamic arrays, 
 and
 associative arrays, that may be difficult to use without the 
 GC:
 http://dlang.org/builtin.html.
4 actually, if you count delegate closures. http://dlang.org/function.html#closures
My apologies for posting a question and then disappearing for eighteen months. I thought it might be useful if I posted some feedback here. We ended up going with Lua here. The main point in favour was the iterative GC which can be interrupted and so can meet deterministic deadlines. I was aware when I posted that it's possible to write D that doesn't use the garbage collector; however, since we want operators to be able to write bits of script that would get compiled and executed, we couldn't see any obvious way of presenting a 'safe' subset of the language; anything we did would either let them do things that would invoke the garbage collector (often in fairly unobvious ways) or enter code that would compile but fail to run (if we built the runtime without the GC). Regards, Tom
Oct 26 2016
parent John Colvin <john.loughran.colvin gmail.com> writes:
On Wednesday, 26 October 2016 at 16:15:19 UTC, Tom wrote:
 My apologies for posting a question and then disappearing for 
 eighteen months.  I thought it might be useful if I posted some 
 feedback here.

 We ended up going with Lua here.  The main point in favour was 
 the iterative GC which can be interrupted and so can meet 
 deterministic deadlines.

 I was aware when I posted that it's possible to write D that 
 doesn't use the garbage collector; however, since we want 
 operators to be able to write bits of script that would get 
 compiled and executed, we couldn't see any obvious way of 
 presenting a 'safe' subset of the language; anything we did 
 would either let them do things that would invoke the garbage 
 collector (often in fairly unobvious ways) or enter code that 
 would compile but fail to run (if we built the runtime without 
 the GC).

 Regards,
 Tom
Did nogc not exist back then?
Oct 26 2016
prev sibling parent Guillaume Piolat <first.last gmail.com> writes:
On Wednesday, 28 January 2015 at 08:12:25 UTC, Mike wrote:
 On Wednesday, 28 January 2015 at 06:58:42 UTC, Tom wrote:
 Or is there now the possibility of disabling the GC altogether,
 or replacing it with a refcounting 'GC' etc?
You can disable the GC:
I think it's important to note that there is three ways to go to minimize GC impact, by order of increasing difficulty: 1. Minimize allocations andthe size of scanned heap. This allows to still use the GC which is handy. Stay at this level if you need only speed. 2. Not enabling the runtime. This forces you to be fully nogc but using the GC is a runtime error instead of a link error. Stay at this level if you need reduced memory consumption. 3. Not link with the runtime, or link with a minimal runtime. This is the hardest way and yield smaller binary size of all, along with the speed and reduced memory consumption. GC avoidance is a spectrum.
Oct 29 2016