Re: Thread-safe reference counts.
On 28 mar, 23:56, "Chris Thomasson" <cris...@comcast.net> wrote:
"Jon Harrop" <use...@jdh30.plus.com> wrote in message
news:13uqrk9au723v0d@corp.supernews.com...
jason.cipri...@gmail.com wrote:
I have some code where objects are dynamically allocated by
some thread, and then used by multiple threads and freed
when they are no longer needed. I think that reference
counting is the most appropriate way to handle this in my
situation.
A concurrent garbage collector is the appropriate way to
handle that situation.
Why? There are many different ways to handle lifetime management.
Just to make it clear: the original posting talked about memory
management, not object lifetime management. From the way it was
presented, it more or less sounded like object lifetime had no
significance (often the case). In which case, garbage
collection is fine. But garbage collection has nothing to do
with object lifetime (which, when significant, still must be
managed, garbage collection or not).
The original poster presented a very concrete problem, for which
garbage collection is probably the best solution, but for which
boost::shared_ptr would probably work almost as well. If he's
already using one, but not the other, then the solution is
obvious. If he's using both, I'd go with garbage collection:
less complexity and less actual coding. If he's using neither,
it depends. Boost::shared_ptr is definitly easier to introduce
into a project, but garbage collection is likely to have more
long term benefits.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34