| Antoine Pitrou | c663b58 | 2010-09-28 23:59:51 +0000 | [diff] [blame] | 1 | .. highlightlang:: c | 
 | 2 |  | 
 | 3 | .. _memoryview-objects: | 
 | 4 |  | 
 | 5 | .. index:: | 
 | 6 |    object: memoryview | 
 | 7 |  | 
 | 8 | MemoryView objects | 
 | 9 | ------------------ | 
 | 10 |  | 
 | 11 | A :class:`memoryview` object exposes the C level :ref:`buffer interface | 
 | 12 | <bufferobjects>` as a Python object which can then be passed around like | 
 | 13 | any other object. | 
 | 14 |  | 
 | 15 |  | 
| Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 16 | .. c:function:: PyObject *PyMemoryView_FromObject(PyObject *obj) | 
| Antoine Pitrou | c663b58 | 2010-09-28 23:59:51 +0000 | [diff] [blame] | 17 |  | 
 | 18 |    Create a memoryview object from an object that provides the buffer interface. | 
 | 19 |    If *obj* supports writable buffer exports, the memoryview object will be | 
 | 20 |    readable and writable, other it will be read-only. | 
 | 21 |  | 
 | 22 |  | 
| Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 23 | .. c:function:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view) | 
| Antoine Pitrou | c663b58 | 2010-09-28 23:59:51 +0000 | [diff] [blame] | 24 |  | 
 | 25 |    Create a memoryview object wrapping the given buffer structure *view*. | 
 | 26 |    The memoryview object then owns the buffer represented by *view*, which | 
| Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 27 |    means you shouldn't try to call :c:func:`PyBuffer_Release` yourself: it | 
| Antoine Pitrou | c663b58 | 2010-09-28 23:59:51 +0000 | [diff] [blame] | 28 |    will be done on deallocation of the memoryview object. | 
 | 29 |  | 
 | 30 |  | 
| Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 31 | .. c:function:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order) | 
| Antoine Pitrou | c663b58 | 2010-09-28 23:59:51 +0000 | [diff] [blame] | 32 |  | 
 | 33 |    Create a memoryview object to a contiguous chunk of memory (in either | 
 | 34 |    'C' or 'F'ortran *order*) from an object that defines the buffer | 
 | 35 |    interface. If memory is contiguous, the memoryview object points to the | 
 | 36 |    original memory. Otherwise copy is made and the memoryview points to a | 
 | 37 |    new bytes object. | 
 | 38 |  | 
 | 39 |  | 
| Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 40 | .. c:function:: int PyMemoryView_Check(PyObject *obj) | 
| Antoine Pitrou | c663b58 | 2010-09-28 23:59:51 +0000 | [diff] [blame] | 41 |  | 
 | 42 |    Return true if the object *obj* is a memoryview object.  It is not | 
 | 43 |    currently allowed to create subclasses of :class:`memoryview`. | 
 | 44 |  | 
 | 45 |  | 
| Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 46 | .. c:function:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj) | 
| Antoine Pitrou | c663b58 | 2010-09-28 23:59:51 +0000 | [diff] [blame] | 47 |  | 
 | 48 |    Return a pointer to the buffer structure wrapped by the given | 
 | 49 |    memoryview object.  The object **must** be a memoryview instance; | 
 | 50 |    this macro doesn't check its type, you must do it yourself or you | 
 | 51 |    will risk crashes. | 
 | 52 |  |