blob: 34ecd12189722d04bb00006f9ccba0a29fbe913f [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
20 readable and writable, other it will be read-only.
21
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
36 original memory. Otherwise copy is made and the memoryview points to a
37 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