Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Using garbage collection in C++

Reply
Thread Tools

Using garbage collection in C++

 
 
Pedro Miguel Carvalho
Guest
Posts: n/a
 
      09-26-2004
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



 
Reply With Quote
 
 
 
 
Dave Rahardja
Guest
Posts: n/a
 
      09-26-2004
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.

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.
 
Reply With Quote
 
 
 
 
Derrick Coetzee
Guest
Posts: n/a
 
      09-26-2004
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
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
 
Reply With Quote
 
Pedro Miguel Carvalho
Guest
Posts: n/a
 
      09-27-2004
"Derrick Coetzee" <(E-Mail Removed)> wrote in message
news:cj7ifv$9ej$(E-Mail Removed)...
| 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


 
Reply With Quote
 
Pedro Miguel Carvalho
Guest
Posts: n/a
 
      09-27-2004
"Dave Rahardja" <(E-Mail Removed)> wrote in message
newsXF5d.40074$(E-Mail Removed)-kc.rr.com...
| 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 .

| 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Garbage Collection after import SteveB ASP .Net 2 10-20-2008 10:35 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Garbage Collection using CMS collector: performance ? Kieran McPeake Java 0 05-30-2006 12:31 AM
using lambda/Proc can prevent a lot of garbage collection Eric Mahurin Ruby 25 10-11-2005 03:01 AM
Templates - Garbage In Garbage Not Out ramiro_b@yahoo.com C++ 1 07-25-2005 04:48 PM



Advertisments