title: What is the most efficient way to pass numpy array to c++ function and return numpy array as output?
body: <p>I've created a shared library. And I'm using it like that</p>
  
  <pre><code>class CAudioRecoveryStrategy(AbstractAudioRecoveryStrategy):
      def __init__(self):
          array_1d_double = npct.ndpointer(dtype=numpy.double, ndim=1, flags='CONTIGUOUS')
          self.lib = npct.load_library("libhello", ".")
  
          self.lib.demodulate.argtypes = [array_1d_double, array_1d_double, ctypes.c_int]
  
      def demodulate(self, input):
          output = numpy.empty_like(input)
          self.lib.demodulate(input, output, input.size)
          return output
  </code></pre>
  
  <p>Right now I have a problem, which is in c++ code I only have pointer to array of output data, not the array. So I can't return the array, unless I manually copy it.</p>
  
  <p>What is the right way to do it? It must be efficient (like aligned memory etc.)</p>