[PyQt] Access to QSharedMemory with buffer protocol

Hans-Peter Jansen hpj at urpla.net
Tue Nov 2 11:57:29 GMT 2010


On Tuesday 02 November 2010, 11:26:46 Giovanni Bajo wrote:
> On mar, 2010-11-02 at 10:16 +0000, Phil Thompson wrote:
> > On Tue, 2 Nov 2010 00:00:06 +0200, "Hans-Peter Jansen"
> > <hpj at urpla.net>
> >
> > wrote:
> > > Hi Phil,
> > >
> > > end of July last year, Alexandre Raczynski asked about accessing
> > > QSharedMemory, and you replied, that:
> > >
> > > mutable_data = buffer(sharedMemory.data())
> > >
> > > ...should give _write_ access to the memory.
> >
> > ...bad advice. I didn't realise that you can't create mutable
> > buffers from Python. (Although there is no reason why you shouldn't
> > be able to.)
>
> Actually, Python 2.7 has memoryview(); if
> memoryview(sharedMemory.data()) worked, it would be possible to use
> memoryview's method to mutate the buffer, without having to come up
> with a different API for sip.voidptr.

Giovanni, isn't memoryview just a different _interface_ to the buffer 
protocol? Anyway, being able to use QSharedMemory with 2.7 and higher 
only looks like an arbitrary restriction to me. At least many of my 
production systems would be locked out, then. For proper support, Phil 
might have to do both variants of the buffer protocol anyway..

Pete


More information about the PyQt mailing list