SGCL - Garbage Collector for C++

S

Sebastian Nibisz

SGCL is precise, parallel garbage collection library for C++ (at this time
for Windows 32/64 only). SGCL is free software published under University of
Illinois/NCSA Open Source License.

Get it at:
http://sourceforge.net/projects/sgcl/

Regards
Sebastian Nibisz
 
M

mosfet

Sebastian Nibisz a écrit :
SGCL is precise, parallel garbage collection library for C++ (at this
time for Windows 32/64 only). SGCL is free software published under
University of Illinois/NCSA Open Source License.

Get it at:
http://sourceforge.net/projects/sgcl/

Regards
Sebastian Nibisz

If you need garbage collection you should try D language.
 
S

Sebastian Nibisz

If you need garbage collection you should try D language.

The D language doesn't have the parallel garbage collector.

Regards
Sebastian Nibisz
 
C

Christopher

SGCL is precise, parallel garbage collection library for C++ (at this time
for Windows 32/64 only). SGCL is free software published under University of
Illinois/NCSA Open Source License.

Get it at:http://sourceforge.net/projects/sgcl/

Regards
Sebastian Nibisz

Garbage collection is for lazy rich folks who can't be bothered to
take out their own trash.
 
S

Sebastian Nibisz

Garbage collection is for lazy rich folks who can't be bothered to
take out their own trash.

struct node
{
node* next;
};

node* root = new node;
node* n = root;

for (int x = 0; x < 1000000; ++x)
{
n = n->next = new node;
}

How to release memory?
 
A

Alberto Bignotti

node* root = new node;
node* n = root;

for (int x = 0; x < 10; ++x)
{
n = n->next = new node;
n->next = 0;
}

n=root;
while(n){
root=n;
n=n->next;
delete root;
}

is that 6 lines too much for you?
if your reply is yes then use a GC.
Be happy.
 
E

Erik Wikström

struct node
{
node* next;
};

node* root = new node;
node* n = root;

for (int x = 0; x < 1000000; ++x)
{
n = n->next = new node;
}

How to release memory?

A recursive function?
 
P

Phil Endecott

Sebastian said:
struct node
{
node* next;
};

node* root = new node;
node* n = root;

for (int x = 0; x < 1000000; ++x)
{
n = n->next = new node;
}

How to release memory?

std::list<>
or boost::intrusive::list<>
or struct node { smart_pointer<node> next; };
or explicit destruction as Alberto described
or allocation from a pool which is all deallocated together
or garbage collection.

All have their advantages and disadvantages. Personally I'm happy with
std::list 99% of the time. I'm actually quite curious to know what sort
of applications or users use garbage collection in C++, but I fear that
it's the sort of discussion that can deteriorate....


Phil.
 
M

Marcel Müller

Sebastian said:
struct node
{
node* next;
};

node* root = new node;
node* n = root;

for (int x = 0; x < 1000000; ++x)
{
n = n->next = new node;
}

How to release memory?

struct node
{ // content...
};

std::slist<boost::shared_ptr<node> > ?


or


struct node
{ boost::shared_ptr<node> next;
};


or if you look for very high performant solutions try
boost::intrusive_ptr which allows very small memory footprints of your
nodes because no additional heap objects are allocated at all.


In fact the only domain of GC solutions are complex data structures with
many cyclic references and without a parent child relation.


Marcel
 
J

James Kanze

On 2008-02-28 17:26, Sebastian Nibisz wrote:
A recursive function?

:).

Smart pointers. We all know that boost::shared_ptr is the
answer to all questions concerning pointers. So just replace
all of the pointers with boost::shared_ptr< node >.

Of course, this problem does have a fairly simple solution.
Most memory management problems do. It's just that it's not
always the same solution, so you have to do considerable
analysis to find it. I use the Boehm collector in new projects,
and it saves development time.
 
S

Sebastian Nibisz

or
struct node
{ boost::shared_ptr<node> next;
};

{
for (int x = 0; x < 1000000; ++x)
{
n = n->next = shared_ptr<node>(new node);
}
} // <- STACK OVERFLOW


rgds
Sebastian Nibisz
 
J

Jeff Schwab

Sebastian said:
struct node
{
node* next;
};

node* root = new node;
node* n = root;

for (int x = 0; x < 1000000; ++x)
{
n = n->next = new node;
}

How to release memory?

It's hard to guess why you would allocate nodes that way in the first place.
 
S

Sebastian Nibisz

{

{
shared_ptr<node> root(new node);
shared_ptr<node> n(root);

for (int x = 0; x < 1000000; ++x)
{
n = n->next = shared_ptr<node>(new node);
}
} // <- recursive destruction (root)

rgds
Sebastian Nibisz
 
S

Sebastian Nibisz

for (int x = 0; x < 10; ++x)
{
n = n->next = new node;
n->next = 0;
}

n=root;
while(n){
root=n;
n=n->next;
delete root;
}

Ok. What if there is a cyclical list?

node* root = new node;
node* n = root;
node* r_n;

int r = rand() % 10;

for (int x = 0; x < 10; ++x)
{
n = n->next = new node;
if (x == r)
{
r_n = n;
}
}

n->next = r_n;
 
J

James Kanze


You're kidding us, right?

Eric was obviously being facious with his suggestion, since it
obviously wouldn't work; I can't imagine anyone not spotting the
problem immediately. The trick about shared_ptr, here, of
course, is that you don't see the recursion, so you may not
realize that you have the same problem until someone explicitly
asks what will happen.

It's really pretty rare that you can recurse 1000000 times
without the stack overflowing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top