LWN.net Logo

Python slithers into Wesnoth

Python slithers into Wesnoth

Posted Jan 18, 2009 12:25 UTC (Sun) by rwmj (guest, #5474)
In reply to: Python slithers into Wesnoth by njs
Parent article: Python slithers into Wesnoth

shared_ptr<> is just reference counting, ie. the worst, slowest, most invasive form of garbage
collection. Please don't confuse this with advanced garbage collectors.


(Log in to post comments)

Python slithers into Wesnoth

Posted Jan 18, 2009 20:44 UTC (Sun) by zlynx (subscriber, #2285) [Link]

Reference counting is "worst" or "best" depending on your requirements. The kind of garbage collection all the "modern" JVMs like to do requires about FIVE TIMES as much RAM as reference counting.

Speaking of garbage collection, it is using reference counting itself. The difference is that a collection cycle counts up the references on the spot instead of tracking them continuously.

The Linux kernel uses reference counting quite a lot. It isn't the only thing used in the kernel, of course. RCU is another RAM hungry technique used there. But the counting seems to work rather well in a kernel, much better than garbage collection.

The Boost collection has some other reference counting options that can work better than shared_ptr, like the intrusive pointers which store the reference count inside the object, giving much better cache locality.

Python slithers into Wesnoth

Posted Jan 18, 2009 21:29 UTC (Sun) by rwmj (guest, #5474) [Link]

I'm assuming by "FIVE TIMES" you're referring to this paper. Unfortunately the paper is flawed with respect to reference counting, because it doesn't include the reference counts - it just assumes that the manually managed version "knows" somehow exactly when to free stuff. With ref counts you bloat every object by 4-8 bytes, and of course that has an effect on cache and memory, which they don't measure. You can find a more detailed response here.

Python slithers into Wesnoth

Posted Jan 19, 2009 3:29 UTC (Mon) by njs (subscriber, #40338) [Link]

> shared_ptr<> is just reference counting, ie. the worst, slowest, most invasive form of garbage collection. Please don't confuse this with advanced garbage collectors.

Good points -- but I'm not sure who you're arguing with?

(Though of course everything old is new again -- I have heard that some cutting-edge true garbage collectors use reference counting because it allows them to optimize reference graph walking -- there cannot exist an unreachable cycle rooted at any object that has not recently had its reference count decremented to a non-zero value. I just like sharing that because while almost certainly useless to know, it's a *super* neat trick.)

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds