[C++-sig] Re: Allocating objects on the heap by default.
dave at boost-consulting.com
Mon Jul 7 21:57:21 CEST 2003
Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> writes:
> Clarifying my own misunderstanding after a little more
> experimentation. :)
>>>>>> "PR" == Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> writes:
> >>> /auto_ptr without having to write a factory function like
> >>> NewObj for every single class?
> DA> class_<Obj, std::auto_ptr<Obj> >("Obj") ...
> DA> ;
> DA> does that.
> PR> Neat. I missed out looking at class_'s HeldType. This solves
> PR> most of my problems here. Wonderful!
> PR> Many thanks! For now I'll add overloads to handle an
> PR> auto_ptr<T> and later consider moving to shared_ptr. I still
> PR> need to get a handle on the performance of shared_ptr though.
> This approach of overloading the functions will not work with the
> HeldType being set to std::auto_ptr since Boost.Python will still call
> the raw pointer version.
If you register the auto_ptr version last it will be preferred.
> So the way around this is to do as you originally said, wrap the add
> function to handle std::auto_ptr and hide the raw pointer interface
> when exposing it to Python.
> PR> The only issue that I need clarification is on how Pyste
> PR> should do handle this. When use_auto_ptr(Obj) is specified
> PR> should it register both the to_python converter and also pass
> PR> the HeldType as auto_ptr or should the HeldType parameter be
> PR> handled by something like handle_with_auto_ptr(Obj)? I think
> PR> the latter is better but am not quite sure. I can submit a
> PR> patch to handle this if this its OK.
> I clearly need to add a separate option because when I specify the
> HeldType a converter from std::auto_ptr seems already registeded for
I'm not sure why that would be.
> Specifically I got the following error when I used use_auto_ptr
> and also passed a HeldType parameter:
> RuntimeError: trying to register to_python_converter for a type
> which already has a registered to_python_converter
> I'll submit a patch to support using auto_ptr or shared_ptr as a
> HeldType sometime tommorow.
More information about the Cplusplus-sig