blob: 9003d3e26d307e896738365e20f1a74e58ed3066 [file] [log] [blame]
Antoine Pitrou6ec5ed22010-09-29 00:01:41 +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
16.. cfunction:: PyObject *PyMemoryView_FromObject(PyObject *obj)
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
23.. cfunction:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view)
24
25 Create a memoryview object wrapping the given buffer structure *view*.
26 The memoryview object then owns the buffer represented by *view*, which
27 means you shouldn't try to call :cfunc:`PyBuffer_Release` yourself: it
28 will be done on deallocation of the memoryview object.
29
30
31.. cfunction:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order)
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
40.. cfunction:: int PyMemoryView_Check(PyObject *obj)
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
46.. cfunction:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj)
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