0

I am trying to extend my python code by creating a c++ module. I am able to import my c++ code by calling 'import my_code' in python with no problem. My issue occurs when I try to return the PyObject. I want to take a vector *settled_nodes_vector that I have created from my c++ code and write the data from that vector as binary data to a buffer and return that buffer. Right now I am doing this:

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

and when I call the following in 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

So my question is how is it that I can't index my information in my result when it is a non-zero length.

  • 1
    I could be wrong but it seems unlikely that the size would really be 20335840, are you sure the problem doesn't lie with code that you haven't shown? – George Nov 15 '16 at 20:05
  • It is rather large, but the original way I worked with this code I was getting around 20MB to 60MB of data when I used to write the results directly to a file in python, so I assume that size number is in bytes, in which case that value is correct. – Big Daddy Software Man Nov 15 '16 at 21:02

0 Answers0