0

我正在尝试通过创建一个 c++ 模块来扩展我的 python 代码。我可以通过在python中调用'import my_code'来导入我的c++代码,没有问题。当我尝试返回 PyObject 时出现我的问题。我想获取从我的 c++ 代码创建的向量 *settled_nodes_vector 并将该向量中的数据作为二进制数据写入缓冲区并返回该缓冲区。现在我正在这样做:

PyBuffer_FromReadWriteMemory((void *) settled_nodes_vector->data(), settled_nodes_vector->size() * sizeof(result_node)));

当我在 python 中调用以下内容时

>>> import my_module
>>> result = my_module.make_buffer()
>>> result
<read-write buffer ptr 0x7fae708c5010, size 20335840 at 0x7fae899577b0>
>>> len(result)
20335840
>>> result[0]
92121 Segmentation fault    (core dumped) python -i

所以我的问题是,当它是非零长度时,我怎么不能在我的结果中索引我的信息。

4

0 回答 0