Re: [Pyobjc-dev] Is it possible to create a CFData without copying bytes?
Brought to you by:
ronaldoussoren
|
From: Uliano G. <gue...@gm...> - 2007-11-12 08:35:19
|
Il giorno 11/nov/07, alle ore 17:24, Ronald Oussoren ha scritto: > > On 11 Nov, 2007, at 16:31, Uliano Guerrini wrote: > >> >> def newf(): >> a=numpy.zeros((256,256),dtype='float32') >> for x in range(0,256): >> a[:,x]=x/255.0 >> return a.tostring() >> >> def cff(): >> return Foundation.CFDataCreateWithBytesNoCopy(None,newf(), >> 65536*4,None) >> >> changing between CFDataCreate and CFDataCreateWithBytesNoCopy makes >> the difference from expected image and crappy noise > > That's the expected behaviour, albeith one that is a bit annoying. well, I'm newbie to pyobjc and to some extent also to python, however I didn't expect (and can't explain) it: it seems to work in a way when I try simple example on the python console and in another inside the image synthesis routine however I found that also NSData.dataWithBytes.NoCopy_Length_ has the same (unexpected for me) behaviour > There is however a better way to convert a python object to an > NSData/CFData without copying: if the object supports the buffer > protocol, which strings and numpy arrays do, you can use > buffer(myObject) to get a buffer object. That object is bridged as > an NSData object, without copying data. this works in that contex, however I don't understand to what extent it is bridged: I passed it to a CF routine and worked as a CFData but does not respond to NSData methods like .bytes() I guess that as this bridged buffer there are other bags of tricks about PyObjc, where can I look for them? uliano |