 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Pedro Miguel Carvalho Guest
|
Posted: Sun Sep 26, 2004 5:34 pm Post subject: Using garbage collection in C++ |
|
|
Greetings.
I'm creating a project that as a intricate relation between object kind of
like a set where each object in the set can be connect to a subset of object
of the set and objects not in the set can connect to objects in the set.
Every object inherits a interface to allow for a mark and sweep garbage
collector (GC) and my implementation works correctly and efficiently but
only in a single thread.
How can I garbage collect in a multi-thread program?
With my garbage collector all threads have to stop what they are doing but
in a coherent state before the garbage collector can do it's job. I could
signal all thread that a garbage collection is needed and wait for all the
treads to be ready then execute the garbage collection but it would mean
that some thread would have to wait (possibly a long time) before all thread
are ready and the garbage collector can start.
I have also tried the Hans-Boehm conservative GC (HBGC) in single-thread
(both the interface for my GC and my GC are off) and it worked correctly. It
takes 5-8% more CPU time, very acceptable, but it uses 79-96% more memory
and that is not acceptable (measured max and mix CPU and memory used in 100
test runs). The test runs uses less CPU time and memory than a full run. In
fact in a full run the HBGC would use virtual memory in my 512 MB
development system and that as you can imagine is a big no-no.
Is this excess memory use normal or am I doing something wrong?
Comments are very much appreciated.
Thanks,
Pedro Carvalho
|
|
| Back to top |
|
 |
Dave Rahardja Guest
|
Posted: Sun Sep 26, 2004 8:49 pm Post subject: Re: Using garbage collection in C++ |
|
|
Pedro Miguel Carvalho wrote:
| Quote: | How can I garbage collect in a multi-thread program?
|
This is off-topic for C++. Try looking for help in an algorithms
newsgroup, or do a search on the subject of thread synchronization.
Hint: interlock the access to your "ready to garbage collect" member
variable. There's no reason why all threads have to stop when you
garbage collect.
|
|
| Back to top |
|
 |
Derrick Coetzee Guest
|
Posted: Sun Sep 26, 2004 11:13 pm Post subject: Re: Using garbage collection in C++ |
|
|
Pedro Miguel Carvalho wrote:
| Quote: | I have also tried the Hans-Boehm conservative GC (HBGC) in single-thread
(both the interface for my GC and my GC are off) and it worked correctly. It
takes 5-8% more CPU time, very acceptable, but it uses 79-96% more memory
and that is not acceptable (measured max and mix CPU and memory used in 100
test runs). The test runs uses less CPU time and memory than a full run. In
fact in a full run the HBGC would use virtual memory in my 512 MB
development system and that as you can imagine is a big no-no.
|
Hans-Boehm should work fine. If you want to avoid the extra storage it
requires between collection cycles, try adding a reference-counting
mechanism to some of your acyclic structures (for example, by using
smart pointers to refer to them). Then there will be less garbage
building up between cycles. You may also be able to make it collect more
often, or when usage reaches a certain level.
--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
|
|
| Back to top |
|
 |
Pedro Miguel Carvalho Guest
|
Posted: Mon Sep 27, 2004 10:20 am Post subject: Re: Using garbage collection in C++ |
|
|
"Derrick Coetzee" <dcnews (AT) moonflare (DOT) com> wrote
| Quote: | Pedro Miguel Carvalho wrote:
I have also tried the Hans-Boehm conservative GC (HBGC) in single-thread
(both the interface for my GC and my GC are off) and it worked
correctly. It
takes 5-8% more CPU time, very acceptable, but it uses 79-96% more
memory
and that is not acceptable (measured max and mix CPU and memory used in
100
test runs). The test runs uses less CPU time and memory than a full run.
In
fact in a full run the HBGC would use virtual memory in my 512 MB
development system and that as you can imagine is a big no-no.
Hans-Boehm should work fine. If you want to avoid the extra storage it
requires between collection cycles, try adding a reference-counting
mechanism to some of your acyclic structures (for example, by using
smart pointers to refer to them). Then there will be less garbage
building up between cycles. You may also be able to make it collect more
often, or when usage reaches a certain level.
--
Derrick Coetzee
|
One of my implementations uses reference-counting smart-pointers for some
objects but for the data set I use a mark-sweep GC. I'm trying to use a GC
because of the extensive cycles that form on my data set so basic
reference-counting will not be a solution. If I make the Hans-Boehm
collector work more then it's use of the CPU also increases.
Thanks,
Pedro Carvalho
|
|
| Back to top |
|
 |
Pedro Miguel Carvalho Guest
|
Posted: Mon Sep 27, 2004 10:36 am Post subject: Re: Using garbage collection in C++ |
|
|
"Dave Rahardja" <ask (AT) me (DOT) com> wrote
| Quote: | Pedro Miguel Carvalho wrote:
How can I garbage collect in a multi-thread program?
This is off-topic for C++. Try looking for help in an algorithms
newsgroup, or do a search on the subject of thread synchronization.
|
Sorry about that. I looked for an appropriate newsgroup. I found various
*.graphics.algorithms, not appropriate, and various *.comp.algorithms, none
in english. I will try in comp.programming.threads, not exactly what I need,
another off-topic .
| Quote: | Hint: interlock the access to your "ready to garbage collect" member
variable. There's no reason why all threads have to stop when you
garbage collect.
|
To garbage collect the data set I have to be certain that I see a consistent
state, other GC use write/read barriers for this.
Thanks,
Pedro Carvalho
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|