[Python.NET] Efficient copy of .NET Array to ctypes or numpy array.

Brad Friedman brad at fie.us
Wed May 21 16:32:23 CEST 2014


An aside that may be useful:

.net will skip array bounds checking within simple for-loops, as an optimization. But only if the binaries have all their optimizations turned on. A binary built for debug has them turned off. There is a huge speed up for iterating over an array when these optimizations are used. So make sure you are not looking at a compiler optimization configuration problem. 

> On May 21, 2014, at 3:21 AM, Dave Cook <daverz at gmail.com> wrote:
> 
> I need to copy a .NET Array (e.g. Double[] or Byte[]) to a numpy array, but it seems the only way to do so is element by element, which is very slow.  Since we are copying a lot of data in real time, it creates a real bottleneck.
> 
> Alternatively, efficient conversion of the .NET array to a Python style byte string would allow numpy.fromstring() to be used for creating the numpy array.
> 
> (I see a similar question went unanswered on the list in August 2011, but I was hoping someone may have figured it out by now.)
> 
> Thanks,
> Dave Cook
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> https://mail.python.org/mailman/listinfo/pythondotnet


More information about the PythonDotNet mailing list