title: Cython typed memoryviews: what they really are?
body: <p>The Cython <a href="http://docs.cython.org/src/userguide/memoryviews.html" rel="noreferrer">documentation</a> explains very well what they allow for, how you can declare them, and how to use them.</p>
  
  <p>However, it is still not clear to me what they really are. For example, a simple assignment from a numpy array like this:</p>
  
  <pre><code>my_arr = np.empty(10, np.int32)
  cdef int [:] new_arr = my_arr
  </code></pre>
  
  <p>can make the accessing/assignment of <code>my_arr</code> faster.</p>
  
  <p>What is it happening behind the scenes? Numpy should already allocate the elements in memory in a contiguous fashion, so what's the deal with memoryviews? Apparently not that much, in fact the memoryview assignment of the numpy array <code>new_arr</code> should be equivalent to </p>
  
  <pre><code>cdef np.ndarray[np.int32_t, ndim=1] new_arr = np.empty(10, np.int32)
  </code></pre>
  
  <p>in terms of speed. However, memoryviews are considered more general than numpy array buffer; could you make a simple example in which the added 'generalization' is important/interesting?  </p>
  
  <p>Furthermore, if I have already allocated a pointer in order to make things as fast as possible, what is the advantage of casting it to a typed memoryview? (the answer to this question might be the same of the one above)</p>
  
  <pre><code>cdef int *my_arr = &lt;int *&gt; malloc(N * sizeof(int))
  cdef int[:] new_arr = &lt;int[:N]&gt;my_arr
  </code></pre>