Pelokalan
Python ID
id en
Masuk
Proyek
c-api__buffer.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
Certain objects available in Python wrap access to an underlying memory array or *buffer*. Such objects include the built-in :class:`bytes` and :class:`bytearray`, and some extension types like :class:`array.array`. Third-party libraries may define their own types for special purposes, such as image processing or numeric analysis.
Objek tertentu yang tersedia dalam Python membungkus akses ke larik memori atau *buffer* yang mendasari. Objek tersebut termasuk built-in :class:`bytes` dan :class:`bytearray`, dan beberapa tipe ekstensi seperti :class:`array.array`. Pustaka pihak ketiga dapat menentukan jenisnya sendiri untuk tujuan khusus, seperti pemrosesan gambar atau analisis numerik.
Python provides such a facility at the C and Python level in the form of the :ref:`buffer protocol <bufferobjects>`. This protocol has two sides:
on the producer side, a type can export a "buffer interface" which allows objects of that type to expose information about their underlying buffer. This interface is described in the section :ref:`buffer-structs`; for Python see :ref:`python-buffer-protocol`.
Simple objects such as :class:`bytes` and :class:`bytearray` expose their underlying buffer in byte-oriented form. Other forms are possible; for example, the elements exposed by an :class:`array.array` can be multi-byte values.
An example consumer of the buffer interface is the :meth:`~io.BufferedIOBase.write` method of file objects: any object that can export a series of bytes through the buffer interface can be written to a file. While :meth:`!write` only needs read-only access to the internal contents of the object passed to it, other methods such as :meth:`~io.BufferedIOBase.readinto` need write access to the contents of their argument. The buffer interface allows objects to selectively allow or reject exporting of read-write and read-only buffers.
Contrary to most data types exposed by the Python interpreter, buffers are not :c:type:`PyObject` pointers but rather simple C structures. This allows them to be created and copied very simply. When a generic wrapper around a buffer is needed, a :ref:`memoryview <memoryview-objects>` object can be created.
As a special case, for *temporary* buffers that are wrapped by :c:func:`PyMemoryView_FromBuffer` or :c:func:`PyBuffer_FillInfo` this field is ``NULL``. In general, exporting objects MUST NOT use this scheme.