[ace-users] ACE + Boost, was: Incorrect Makefile.am code generate for a conditional binaryprogram

[ace-users] ACE + Boost, was: Incorrect Makefile.am code generate for a conditional binaryprogram

Post by Zsolt Baye » Sat, 05 Feb 2005 14:33:42


avid,

You need to be careful about Boost shared pointers as
the reference gets stored with the pointer and not the
object. The pointer creates a heap object where the
reference is stored. This heap object is handed from
pointer to pointer when new pointers are created and
hence they all end up referring to the same reference
count.

Unfortunately, this does not work in some cases, like
a double dispatch pattern, when the new pointer does
not get to "see" the original pointer. In such a
case, a new reference may be created, and you end up
having 2 reference counts for the same object. Now,
when one of these goes to 0, your object gets deleted,
even though you may have other pointers still pointing
to the object (that is why you hit deleted
synchronisation objects).

Therefore, you need to be very careful when using this
kind of a pointer. It is much better to store the
reference with the object itself, however, you then
need to modify your original object (inherit from a
refcounter class), which may not always be possible
(in case of libraries, etc). ACE pointers are like
this from memory.

I never liked the Boost pointer. We are now using
both Boost and ACE, but ended up coding our own
version of smart pointers still. This was due to the
fact that even ACE did not support some nice features,
like polymorphism. We now have virtually a TRUE smart
pointer, and never use dumb pointer any more unless it
is a must in exceptional circumstances (back pointers,
to break header file dependencies, etc).

I recommend that you keep using the ACE pointers. If
you need more info, refer to Scott Meyer's More
Effective C++, where he has a whole section on smart
pointers. Hope this helps.

Zsolt Bayer

have
collection, in

definition).
with very
code that was
then
lockups
ACE_Strong_Bound_Ptr and
ACE
PXE booted
this.
templates
(perhaps
systems).


Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com