Re: [ctypes-users] copying/slicing ctypes arrays, (c_ulong *n)()
Brought to you by:
theller
From: Ray S. <rj...@bl...> - 2005-02-02 22:15:31
|
At 10:09 PM 2/2/2005 +0100, Thomas Heller wrote: >RayS <ra...@bl...> writes: > > > Alternatively, do you expect to implement the acceptance of Python > > objects which implement the buffer interface in the near future? > >I hope to be able to make a new release this or next week. So far, I >think objects implementing the buffer interface should *not* be allowed >as function parameters, but *buffer objects* should be. The reason is >that the former would break too much code. > >IIUC, you should then be able to call buffer() on a Numeric array >instance and pass that to a function, or call buffer() on the _data >member of a Numarray array instance. > >The buffer() object has been changed in Python 2.4 (or was it even 2.3?) >so that it retrieves the memory block address from the original object >each time it is needed, instead of getting it once and then storing it >permanently. So it should be even safe if the original object changes >its internal memory block. Ahh, thanks for the insight. >>> import Numeric, string >>> N=Numeric.zeros((100,), Numeric.Float) >>> repr(N.__copy__) '<built-in method __copy__ of array object at 0x007B10B8>' >>> buffer(N, 0, 0) <read-only buffer for 0x007B10B8, ptr 0x00809A98, size 0 at 0x0082B0D0> >>> buffer(N, 50, 50) <read-only buffer for 0x007B10B8, ptr 0x00809ACA, size 50 at 0x00828E98> >>> string.split(buf.__repr__())[5] '0x00809A98,' >>> int(string.split(buf.__repr__())[5][:-1], 16) 8428184 I presume (!) that the ptr address could be passed to ctypes.memmove() At least, I'll try; memmove() does work fine with numarray.info address. The desire is to write form the ctypes DLL call into the Numeric array, so actually using the buffer(N) is out. Ray |