How can I guarantee that the same Python instance is always returned for a specific C ++ instance?

I am using Boost.Python to wrap a C ++ library.

How to ensure that the same Python instance (by object identifier) ​​is always returned for a specific C ++ instance (by pointer identifier)? I cannot extend C ++ classes, but I can add a member variable (e.g. PyObject * or boost :: python :: handle <>) if that helps. I think I should be able to cache a Python instance in a C ++ instance and return a cache instance instead of creating a new one. However, I cannot figure out which batch code is required.

Example class for packaging:

class C {
public:
    boost::python::handle<> wrapper_;

private:
    C();
    C(const C &);
    ~C();
};

Can anyone offer advice?

+3
1

, , , . , id() ( ) -, ++.

++ - , . .

+1

Source: https://habr.com/ru/post/1753210/


All Articles