www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - switch off GC?

reply Weed <resume755 mail.ru> writes:
It is possible to disable GC?

That it has not been included in result binary for an increasing
performance of ref operations and reduction of the size of the binary

I have not found the answer in google.
Feb 03 2009
next sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Weed wrote:
 It is possible to disable GC?
Yes. See std.gc or tango.core.Memory.
 That it has not been included in result binary for an increasing
 performance of ref operations and reduction of the size of the binary
I don't know what "ref operations" are, but odds are disabling the GC will not alter their performance. Disabling the GC just prevents collections from occurring. Collections ONLY occur during allocation, so the only thing you'll speed up are allocations. Whilst it's possible to replace the GC in D, it's not exactly straightforward. I'm not sure what the situation with Phobos is, but last I checked, the GC is built as part of Phobos, so you would need to make a custom version. Tango is slightly better in this respect; the GC is compiled separately, and is then linked in. I also believe Tango has a "stub" GC that doesn't actually do any garbage collection; you just need to link that in instead of the proper GC. -- Daniel
Feb 03 2009
prev sibling next sibling parent Jesse Phillips <jessekphillips gmail.com> writes:
On Wed, 04 Feb 2009 09:38:45 +0700, Weed wrote:

 It is possible to disable GC?
 
 That it has not been included in result binary for an increasing
 performance of ref operations and reduction of the size of the binary
 
 I have not found the answer in google.
You can find some more answers, though not much about how to replace it. http://stackoverflow.com/questions/472133/turning-off-the-d-garbage- collector
Feb 03 2009
prev sibling next sibling parent reply "Tim M" <a b.com> writes:
On Wed, 04 Feb 2009 15:38:45 +1300, Weed <resume755 mail.ru> wrote:

 It is possible to disable GC?

 That it has not been included in result binary for an increasing
 performance of ref operations and reduction of the size of the binary

 I have not found the answer in google.
To anyone here that disables there GC: Whats you reason for doing this? (Note: I don't want to know possible requirements but just your reason just out of interest)
Feb 04 2009
next sibling parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Tim M wrote:
 On Wed, 04 Feb 2009 15:38:45 +1300, Weed <resume755 mail.ru> wrote:
 
 It is possible to disable GC?

 That it has not been included in result binary for an increasing
 performance of ref operations and reduction of the size of the binary

 I have not found the answer in google.
To anyone here that disables there GC: Whats you reason for doing this? (Note: I don't want to know possible requirements but just your reason just out of interest)
I've never attempted to remove it entirely, but have often disabled it. There are two basic scenarios where I've done this. One, where I have a block of code that either really needs to run at full speed or just plain allocates a whole lot of memory in multiple chunks. In this case, I am delaying the inevitable collection run. The second case, is a program of mine that expects to run for very long periods (months, if all goes well), and also needs to be very responsive to work right. In this case, I keep the GC disabled and trigger collections at my own choice of key moments (database checkpoints, etc) where responsiveness is /expected/ to be temporarily lacking. -- Chris Nicholson-Sauls
Feb 04 2009
prev sibling parent Heinz <malagana15 yahoo.es> writes:
Tim M Wrote:

 On Wed, 04 Feb 2009 15:38:45 +1300, Weed <resume755 mail.ru> wrote:
 
 It is possible to disable GC?

 That it has not been included in result binary for an increasing
 performance of ref operations and reduction of the size of the binary

 I have not found the answer in google.
To anyone here that disables there GC: Whats you reason for doing this? (Note: I don't want to know possible requirements but just your reason just out of interest)
Just for interest in some optimization: I disable it (but replace it) in DLL's, i mean, there's no need to have 2 GC running at a time (one for the exe and one for the DLL), so i disable the one in the dll and then replace it with the same from the exe. I link my dll with gcstub.obj to use a dummy gc so file size is smaller. So after all...i never disable gc. GC is a good feature, i always use it in executables but when i do a gc full collect under heavy load programs (great amount of mb of ram) the thing gets quiet slow.
Feb 08 2009
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Weed, some built-ins and significant part of the standard lib (and other libs
you can find around) assume the presence of a GC.
So you can disable (or often just not use it. If you don't allocate/free
GC-managed memory then the GC sleeps) in some critical spots of your code as I
do (and you can also just use memory from the C heap), but if you really want
to remove it, you may want to consider using C++ instead.

I'd like too to have something like a -nogc compiler flag to not include the GC
at all in small programs that don't use the GC (or use it only to allocate
memory and not to free it).

Bye,
bearophile
Feb 04 2009
parent reply Weed <resume755 mail.ru> writes:
bearophile пишет:
 Weed, some built-ins and significant part of the standard lib (and other libs
you can find around) assume the presence of a GC.
Right. For example, return from function of a dynamic array will not work correctly without GC - there will be a memory leak.
 So you can disable (or often just not use it. If you don't allocate/free
GC-managed memory then the GC sleeps) in some critical spots of your code as I
do (and you can also just use memory from the C heap), but if you really want
to remove it, you may want to consider using C++ instead.
 
 I'd like too to have something like a -nogc compiler flag to not include the
GC at all in small programs that don't use the GC (or use it only to allocate
memory and not to free it).
My wishlist also contains -nogc (or may be -gc?) too. But it seems to me it will not occur - too many parts of language mean presence GC. I just would like that D could substitute C++ completely in all applications...
Feb 04 2009
next sibling parent Kagamin <spam here.lot> writes:
Weed Wrote:

 I just would like that D could substitute C++ completely in all
 applications...
D can do it. Phobos and Tango - can't.
Feb 05 2009
prev sibling parent Lutger <lutger.blijdestijn gmail.com> writes:
Weed wrote:
 
 I just would like that D could substitute C++ completely in all
 applications...
D2 can easily, but it seems there is not so much interest if measured by what library code is available. D1 can do too, but if you want to use raii for memory management D2 has better facilities. In all fairness, those language features that use GC don't exist in C++.
Feb 05 2009