Thanks all: At 10:00 AM 10/10/2007, Robert Kern wrote: >Something like the following should suffice (untested, though I've >done similar things with ctypes before):
I tested, successfully: """ nFromAddress.py """ def fromaddress(address, dtype, shape, strides=None): """ Create a numpy array from an integer address, a dtype or dtype string, a shape tuple, and possibly strides. """ import numpy # Make sure our dtype is a dtype, not just "f" or whatever. dtype = numpy.dtype(dtype) class Dummy(object): pass d = Dummy() d.__array_interface__ = dict( data = (address, False), typestr = dtype.str, descr = dtype.descr, shape = shape, strides = strides, version = 3, ) return numpy.asarray(d) ## Numeric example, with address kludge import Numeric, numpy, ctypes, string a0 = Numeric.zeros((10000), Numeric.Int16) nAddress = int(string.split(repr(a0.__copy__))[-1][:-1], 16) tmp=(ctypes.c_long*1)(0) ctypes.memmove(tmp, nAddress+8, 4) nAddress = tmp[0] a1 = fromaddress(nAddress, numpy.int16, (10000,)) ## explicit type a0[0] = 5 print a1[0] ## numpy example a2 = numpy.zeros(10000, numpy.int16) nAddress = a2.__array_interface__['data'][0] nType = a2.__array_interface__['typestr'] nShape = a2.__array_interface__['shape'] a3 = fromaddress(nAddress, nType, nShape) a2[0] = 5 print a3[0] So, now with little effort the relevant info can be passed over pipes, shared memory, etc. and shares/views created in other processes, since they are not objects but ints and strings. >David Cournapeau Wrote: >Basically, you cannot expect file descriptors (or even file handles: >the >standard ones from C library fopen) to cross dll boundaries if the >dll do not have exactly the same runtime. It sounds like there is a general dilemma: no one with Python 2.4 or 2.5 can reliably expect to compile extensions/modules if they did not install the 7.1 compiler in time. The 2.6 seems to use VC 2005 Express, I don't know about py3000(?), with associated upgrade issues. It would be nice if the build bots could also compile suggested modules/extentions. Thanks again, Ray _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion