boost python中的enable_pickling和pickle_suite有啥区别?

Posted

技术标签:

【中文标题】boost python中的enable_pickling和pickle_suite有啥区别?【英文标题】:What is the difference between enable_pickling and pickle_suite in boost python?boost python中的enable_pickling和pickle_suite有什么区别? 【发布时间】:2020-07-16 16:07:53 【问题描述】:

我有一个相当大的类,它有大约 40 个属性,但只有 15 个作为参数传递给构造函数:

class MyClass
    /*40 attributes here*/
    MyClass(/*15 args here, the rest are initialized at default values*/);
;

我正在尝试为这个类实现泡菜支持,到目前为止boost.python documentation 似乎表明我可以实现pickle_suite 类的实例,或者我可以只做.enable_pickling() 并让python处理剩下的。与仅使用一行代码相比,花时间实现所有 __getinitargs__ 和其他东西有什么优势吗?据我了解,酸洗本质上是将对象转换为一堆 1 和 0 并传递它。

谢谢

【问题讨论】:

【参考方案1】:

没关系,看起来普通的 python pickler 无法复制容器内的元素,如 std::vector 或 std::pair

【讨论】:

以上是关于boost python中的enable_pickling和pickle_suite有啥区别?的主要内容,如果未能解决你的问题,请参考以下文章