24.7. C++ and the Python Buffer Protocol

Python’s buffer protocol is a general purpose wrapper around data structures that contain homogeneous types with a regular structure. Examples are numpy ndarrays, PIL images and Python types such as bytes, bytearray and array.array types.

The buffer protocol is described in PEP 3118.

The great advantage of this is that it uses a shared memory model so that the data can be passed between Python or C++ without copying.

It is fairly straightforward to create a C++ wrapper class around the buffer protocol.

Todo

Complete the Buffer Protocol chapter with examples from RaPiVot and the C++ wrapper code.

24.7.1. References: