473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

Jul 22 '05 #1
4 2013
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.
Jul 22 '05 #2
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.
Jul 22 '05 #3
"Derrick Coetzee" <dc****@moonflare.com> wrote in message
news:cj**********@news-int.gatech.edu...
| 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
Jul 22 '05 #4
"Dave Rahardja" <as*@me.com> wrote in message
news:pX*******************@twister.rdc-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
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and...
0
by: Andrew | last post by:
When will .NET have a low-pause-time garbage collector A low-pause-time garbage collector would greatly improve .NET's ability to serve as a platform for soft real-time systems. It doesn't have...
6
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
11
by: Rick | last post by:
Hi, My question is.. if Lisp, a 40 year old language supports garbage collection, why didn't the authors of C++ choose garbage collection for this language? Are there fundamental reasons behind...
5
by: Bob lazarchik | last post by:
Hello: We are considering developing a time critical system in C#. Our tool used in Semiconductor production and we need to be able to take meaurements at precise 10.0 ms intervals( 1000...
6
by: Andy | last post by:
Along with many others I've noticed the large amount of memory that can be taken up by the aspnet_wp.exe. I've found that I can better control and limit this memory consumption by including a...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
53
by: None | last post by:
Hi, I am a game developer, sometimes "indy" and sometimes for a small-sized company. I can't speak for all game developers, but everywhere I've ever seen people working on games, execution...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.