Call Policy for Singleton
HI, The am not sure if which call policy I should be using for this particular use case, class Singleton { public: Singleton* create() { if(!_instance) { _instance = new Singleton(); } return _instance; } static Singleton* _instance; } // Initialization Singleton* _instance=NULL; Is return_value_policy<reference_existing_object> the right call policy to use? Thanks, Shiva
I think reference_existing_object will work. And in my opinion, you'd better be careful if you expect that the c++ code and python code are using the same singleton instance. Because there're two Singleton::_instance if you export the Singleton class to Python. one at c++ side, the other at python side. 2009/2/13 Balasubramanyam, Shivakumar <sbalasub@qualcomm.com>
HI,
The am not sure if which call policy I should be using for this particular use case,
class Singleton { public: Singleton* create() { if(!_instance) { _instance = new Singleton(); } return _instance; } static Singleton* _instance; }
// Initialization Singleton* _instance=NULL;
Is return_value_policy<reference_existing_object> the right call policy to use?
Thanks, Shiva
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
-- Time is mana, we must hurry
ZaeX wrote:
And in my opinion, you'd better be careful if you expect that the c++ code and python code are using the same singleton instance. Because there're two Singleton::_instance if you export the Singleton class to Python. one at c++ side, the other at python side. I don't think this is true. What makes you think this?
John.
When the Singleton class is linked, the DLL will get the Singleton::_instance as an unique static variable. Well, In my last attempt, it appeared to be like that. On Fri, Feb 13, 2009 at 5:33 PM, John Reid <j.reid@mail.cryst.bbk.ac.uk>wrote:
ZaeX wrote:
And in my opinion, you'd better be careful if you expect that the c++ code and python code are using the same singleton instance. Because there're two Singleton::_instance if you export the Singleton class to Python. one at c++ side, the other at python side.
I don't think this is true. What makes you think this?
John.
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
-- Time is mana, we must hurry
participants (3)
-
Balasubramanyam, Shivakumar -
John Reid -
ZaeX