title: Cython: Returning C buffer memoryview to Python
body: <p>I have following Cython code with one C buffer defined (<code>c_buffer</code>):</p>
  
  <pre><code>ctypedef struct my_struct_t:
      float x
      float y
  
  cdef class CMyClass:
      cdef my_struct_t c_buffer[1000]
  
      def get_array(self):
          return &lt;my_struct_t[:1000]&gt;&amp;self.c_buffer[0]
  
      def get_memoryview(self):
          return memoryview(&lt;my_struct_t[:1000]&gt;&amp;self.c_buffer[0])
  </code></pre>
  
  <p>I'm using this class to store elements that eventually go to OpenGL VBO buffer. What I'm trying to do is avoid unnecessary copies of memory.</p>
  
  <p>When I call <code>get_array()</code> I get result of type </p>
  
  <pre><code>&lt;c_wrappers.array object at 0x7fffce17d650&gt;
  </code></pre>
  
  <p>with <code>get_memoryview()</code> the result is:</p>
  
  <pre><code>&lt;memory at 0x7fffd242e648&gt;
  </code></pre>
  
  <ol>
  <li><p>What's the difference between them (in functionality/speed)? I'm reading official document in about <a href="https://cython.readthedocs.io/en/latest/src/userguide/memoryviews.html" rel="nofollow noreferrer">Typed Memoryviews</a>, but it focuses mainly on numpy. Am I returning the memoryviews here correctly?</p></li>
  <li><p>Now the buffer is fixed (max 1000 elements). Does in Cython exist dynamic array that I could use and it automatically handles memory for me (for adding/removing elements at runtime) and having continuous memory layout (that I could eventually supply to OpenGL VBO)? Or should I use <code>from libcpp.vector cimport vector</code>?</p></li>
  </ol>