Re: [ctypes-users] copying/slicing ctypes arrays, (c_ulong *n)()
Brought to you by:
theller
From: Thomas H. <th...@py...> - 2004-12-16 16:09:20
|
RayS <ra...@bl...> writes: > Thanks Florian, > > My preliminary assessment from trials yesterday (based only on a rough > benchmark of idle time) is that > for i in range(2000): numArray[pntr+i] = buf[i] > is >10x slower than > numArray[pntr:pntr+2000] = map(None, buf) > which is 25% slower than using array.array() & memmove > memmove(array.buffer_info()[0]+pntr, buf) > Do I understand it correctly that memmove is only slightly faster than the 'numArray[..] = map(None, buf)' call? If so, interesting. > I'll test the direct assignment today, as below, as subsequent > operations on numarray should be faster than array. I don't recall why > I didn't. > > The numarray buffer interface is interesting, but I mainly need to do > a (deep) copy out of the ctypes memory. Since the main issue is that > src (the ctypes obj) is being updated with 2KB A/D data @125x per > second (250K samp./s), I need to get it out of the cytpes obj into > storage as efficiently as possible. That storage must then work with > slicing and FFT. > > If the ctypes construct buf = (c_ulong * 2000)() supported slicing, I > would just leave it there... But it *should* support slicing. Can't you write this instead of the map() call? numArray[pntr:pntr+2000] = buf[0:2000] Another possibility would be to let the ADC write the data directly into the numArray, once you know it's address (and assuming it doesn't change). Thomas |