473,951 Members | 30,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SGCL - Garbage Collector for C++

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

Feb 28 '08
72 3522
Sebastian Nibisz schrieb:
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<boos t::shared_ptr<n ode ?
or
struct node
{ boost::shared_p tr<nodenext;
};
or if you look for very high performant solutions try
boost::intrusiv e_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
Feb 28 '08 #11
or
>
struct node
{ boost::shared_p tr<nodenext;
};
{
for (int x = 0; x < 1000000; ++x)
{
n = n->next = shared_ptr<node >(new node);
}
} // <- STACK OVERFLOW
rgds
Sebastian Nibisz
Feb 28 '08 #12
Erik Wikström schrieb:
On 2008-02-28 17:26, Sebastian Nibisz wrote:
>>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 recursive function?
Stack overflow?

--
Thomas
http://www.netmeister.org/news/learn2quote.html
To iterate is human, to recurse divine.
-L. Peter Deutsch
Feb 28 '08 #13
Sebastian Nibisz wrote:
>or

struct node
{ boost::shared_p tr<nodenext;
};

{
for (int x = 0; x < 1000000; ++x)
{
n = n->next = shared_ptr<node >(new node);
}
} // <- STACK OVERFLOW
Why?
Feb 28 '08 #14
Sebastian Nibisz wrote:
>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?
It's hard to guess why you would allocate nodes that way in the first place.
Feb 28 '08 #15
>{
> for (int x = 0; x < 1000000; ++x)
{
n = n->next = shared_ptr<node >(new node);
}
} // <- STACK OVERFLOW

Why?
{
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
Feb 28 '08 #16
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;

Feb 28 '08 #17
>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.
The parent must know the child.

rgds
Sebastian Nibisz

Feb 28 '08 #18
On Feb 28, 7:25 pm, Phil Endecott <spam_from_usen et_0...@chezphi l.org>
wrote:
Sebastian Nibisz wrote:
or
struct node
{ boost::shared_p tr<nodenext;
};
{
for (int x = 0; x < 1000000; ++x)
{
n = n->next = shared_ptr<node >(new node);
}
} // <- STACK OVERFLOW
Why?
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.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 28 '08 #19
Sebastian Nibisz wrote:
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


Sounds like interesting stuff for anyone who wants to use GC in his/her
applications.

The thread shouldn't turn out to the flame "Do we need garbage
collection"? Anyone that can afford it in his/her applications and wants
to, he/she may use it.
Feb 28 '08 #20

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

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.