Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-10-23 08:13:28


Ovanes Markarian wrote:
> Hello,
>
> we have some application, where boost::shared_ptr is extensively
> used. After profiling with gprof I got that the shared_ptr destructor
> is very expensive. I used following g++ compiler flags to compile:
>
> -Wall -ftemplate-depth-50 -fexceptions -fexpensive-optimizations -O3
>
> Are there may be some MACRO-defs, which can enable/disable some
> additional optimizations?

First, you need to determine where the time is being spent. Typically,
~shared_ptr for the last instance performs two atomic decrements and two
'delete p' operations; the first delete calls the destructor of your object,
the second destroys the control block, and there are two calls to operator
delete.

What is your platform? You may try to play with #define
BOOST_SP_USE_QUICK_ALLOCATOR and see if it helps. See
shared_ptr_alloc_test.cpp for an example. If your application is single
threaded, you can try BOOST_SP_DISABLE_THREADS (although I don't believe
that the problem is with the atomics; it's more likely that 'delete' is an
expensive operation for some reason.)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net