[C++-sig] alternative smart pointer (intrusive_ptr) example

David Abrahams dave at boostpro.com
Tue Jul 29 02:53:14 CEST 2008


on Mon Jul 28 2008, Alex Mohr <amohr-AT-pixar.com> wrote:

>>> (2) using a global dictionary to store the Pointee->PyObject mappings
>>
>> Isn't this going to incur comparable memory use to shared_ptr?
>
> We use a global table.
>
> Suppose you have a system where there are hundreds of thousands of
> objects and only some small fraction of them are passed to python.
>
> In this case, adding 8 bytes of overhead to every object versus adding
> 8 bytes of overhead to only those objects passed to python can save
> 100s of KB of memory.  Perhaps that doesn't sound like a lot these
> days, but when your users are always trying to push the hardware and
> software as hard as they possibly can, it can definitely make a
> difference.
>
> Formerly I embedded the python objects inside the C++ objects but
> switched to the global table due to memory usage.

I wasn't talking about adding storage to every instance of a class.

Boost.Python converts any wrapped object of type T to a shared_ptr<T>
which, when passed back to Python, gets converted back to the original
Python object.  The last shared_ptr to that object may be reclaimed when
the C++ code is done using it.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com



More information about the Cplusplus-sig mailing list