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

Alex Mohr amohr at pixar.com
Tue Jul 29 02:20:02 CEST 2008


>> (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.

Alex



More information about the Cplusplus-sig mailing list