Data_as
"West, Peter" <[email protected]> Tue, 30 Dec 2014 17:15:07 +0000
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Hi I need to pass a DLL a pointer to an array of pointers to c arrays of unsigned 16 bit integers. I started to do this using data_as(POINTER( type ) on sub-arrays. This caused access violations. When I looked at what was in the pointer arrays I discovered that they all pointed to the same location. After poking around a bit is seems that the problem is not to do with using sub-arrays as I expected but with the way in which I have approached the problem and I can't see what I'm doing wrong. Here is a very simple example from ctypes import POINTER, c_uint16 import numpy as np if __name__ == '__main__': pointerArrayType = POINTER( c_uint16 ) * 2 # an array of pointers type length 2 pointers = pointerArrayType() # the actual array frame1 = np.zeros(( 100, 100 ), dtype = np.uint16, order = 'C' ) # Ensure C contiguous layout frame2 = np.zeros(( 100, 100 ), dtype = np.uint16, order = 'C' ) pointers[ 0 ] = frame1.ctypes.data_as( POINTER( c_uint16 )) pointers[ 1 ] = frame2.ctypes.data_as( POINTER( c_uint16 )) print pointers[ 0 ] print pointers[ 1 ] This prints <__main__.LP_c_ushort object at 0x00000000025132C8> <__main__.LP_c_ushort object at 0x00000000025132C8> This suggests that the data arrays for frame1 and frame2 are at the same location. Clearly I've done something wrong but can't see what. Any help would be gratefully received. ------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net