[Pyrex] Serialization of a wrapped C structure

Samuele Kaplun Samuele.Kaplun at cern.ch
Wed Aug 1 08:39:08 CEST 2007


In data lunedì 30 luglio 2007, Greg Ewing scribacchiaste dette parole:
> Samuele Kaplun wrote:
> > How can I reach a binary sequence of data in memory to
> > serialize it?
>
> I'm not sure, but if you equip your type with a buffer
> interface, that might enable you to pass it directly
> to struct.pack without requiring an intermediate string
> copy.
>
> You would also probably be able to pass it directly
> to the write method of a file object, if that would
> help. That would be even more efficient as it would
> eliminate copying altogether.
>
> --
> Greg

Hi Greg, 
thanks a lot for the advices, that helped me in learning a lot about Pyrex + 
Python. In the end I used PyString_FromStringAndSize for dumping it to a 
Python string, and PyObject_AsReadBuffer for retrieving the content. 
Best regards,
	Samuele

-- 
.O.
..O
OOO



More information about the Pyrex mailing list