【发布时间】:2010-09-16 08:34:10
【问题描述】:
考虑以下 python ctypes - c++ 绑定:
// C++
class A
{
public:
void someFunc();
};
A* A_new() { return new A(); }
void A_someFunc(A* obj) { obj->someFunc(); }
void A_destruct(A* obj) { delete obj; }
# python
from ctypes import cdll
libA = cdll.LoadLibrary(some_path)
class A:
def __init__(self):
self.obj = libA.A_new()
def some_func(self):
libA.A_someFunc(self.obj)
当不再需要 python 对象时,删除 c++ 对象的最佳方法是什么。
[编辑] 我添加了建议的删除功能,但是问题仍然存在,由谁以及何时调用该函数。应该尽可能方便。
【问题讨论】: