blob: 6b49cdf70a3554310897ac9b810fafa5c608d731 [file] [log] [blame]
Antoine Pitrouc663b582010-09-28 23:59:51 +00001.. highlightlang:: c
2
3.. _memoryview-objects:
4
5.. index::
6 object: memoryview
7
8MemoryView objects
9------------------
10
11A :class:`memoryview` object exposes the C level :ref:`buffer interface
12<bufferobjects>` as a Python object which can then be passed around like
13any other object.
14
15
Georg Brandl60203b42010-10-06 10:11:56 +000016.. c:function:: PyObject *PyMemoryView_FromObject(PyObject *obj)
Antoine Pitrouc663b582010-09-28 23:59:51 +000017
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
Eli Bendersky5a53f362011-11-25 15:07:50 +020020 readable and writable, otherwise it will be read-only.
Antoine Pitrouc663b582010-09-28 23:59:51 +000021
22
Georg Brandl60203b42010-10-06 10:11:56 +000023.. c:function:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view)
Antoine Pitrouc663b582010-09-28 23:59:51 +000024
25 Create a memoryview object wrapping the given buffer structure *view*.
26 The memoryview object then owns the buffer represented by *view*, which
Georg Brandl60203b42010-10-06 10:11:56 +000027 means you shouldn't try to call :c:func:`PyBuffer_Release` yourself: it
Antoine Pitrouc663b582010-09-28 23:59:51 +000028 will be done on deallocation of the memoryview object.
29
30
Georg Brandl60203b42010-10-06 10:11:56 +000031.. c:function:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order)
Antoine Pitrouc663b582010-09-28 23:59:51 +000032
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
Eli Bendersky5a53f362011-11-25 15:07:50 +020036 original memory. Otherwise, a copy is made and the memoryview points to a
Antoine Pitrouc663b582010-09-28 23:59:51 +000037 new bytes object.
38
39
Georg Brandl60203b42010-10-06 10:11:56 +000040.. c:function:: int PyMemoryView_Check(PyObject *obj)
Antoine Pitrouc663b582010-09-28 23:59:51 +000041
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 Brandl60203b42010-10-06 10:11:56 +000046.. c:function:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj)
Antoine Pitrouc663b582010-09-28 23:59:51 +000047
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