title: Creating a Py_buffer from an array in c++
body: <p>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:</p>
  
  <pre><code>PyBuffer_FromReadWriteMemory((void *) settled_nodes_vector-&gt;data(), settled_nodes_vector-&gt;size() * sizeof(result_node)));
  </code></pre>
  
  <p>and when I call the following in python</p>
  
  <pre><code>&gt;&gt;&gt; import my_module
  &gt;&gt;&gt; result = my_module.make_buffer()
  &gt;&gt;&gt; result
  &lt;read-write buffer ptr 0x7fae708c5010, size 20335840 at 0x7fae899577b0&gt;
  &gt;&gt;&gt; len(result)
  20335840
  &gt;&gt;&gt; result[0]
  92121 Segmentation fault    (core dumped) python -i
  </code></pre>
  
  <p>So my question is how is it that I can't index my information in my result when it is a non-zero length. </p>