[C++-sig] can boost::python class imlement buffer protocol?
Neal Becker
ndbecker2 at gmail.com
Thu Jan 8 04:05:24 CET 2009
David Abrahams wrote:
>
> on Wed Jan 07 2009, Neal Becker <ndbecker2-AT-gmail.com> wrote:
>
>> This would require filling in tp_as_buffer field in the PyTypeObject
>> structure for the
>> class. Is this possible? Any clue how/where this could be done?
>
> I honestly don't know the answers to these questions, sorry.
>
As a workaround, I currently implemented an 'as_buffer' member function.
For example:
template<typename T>
inline object as_buffer (ublas::vector<T> & m) {
return object (handle<> (PyBuffer_FromReadWriteMemory ((void*)(&m.data()[0]), m.size()*sizeof(T))));
}
More information about the Cplusplus-sig
mailing list