Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8abc9358
Kaydet (Commit)
8abc9358
authored
Ara 12, 2010
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Better explain the buffer interface (hopefully)
üst
36730e8b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
16 deletions
+26
-16
buffer.rst
Doc/c-api/buffer.rst
+25
-15
typeobj.rst
Doc/c-api/typeobj.rst
+1
-1
No files found.
Doc/c-api/buffer.rst
Dosyayı görüntüle @
8abc9358
...
...
@@ -12,16 +12,32 @@ Buffer Protocol
.. index::
single: buffer interface
Python objects implemented in C can export a "buffer interface." These
functions can be used by an object to expose its data in a raw, byte-oriented
format. Clients of the object can use the buffer interface to access the
object data directly, without needing to copy it first.
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.
Examples of objects that support the buffer interface are :class:`bytes`,
:class:`bytearray` and :class:`array.array`. The bytes and bytearray objects
exposes their bytes contents in the buffer interface's byte-oriented form.
An :class:`array.array` can also expose its contents, but it should be noted
that array elements may be multi-byte values.
While each of these types have their own semantics, they share the common
characteristic of being backed by a possibly large memory buffer. It is
then desireable, in some situations, to access that buffer directly and
without intermediate copying.
Python provides such a facility at the C level in the form of the *buffer
protocol*. This protocol has two sides:
.. index:: single: PyBufferProcs
- 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`;
- on the consumer side, several means are available to obtain a pointer to
the raw underlying data of an object (for example a method parameter).
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 a :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
...
...
@@ -44,12 +60,6 @@ isn't needed anymore. Failure to do so could lead to various issues such as
resource leaks.
.. index:: single: PyBufferProcs
How the buffer interface is exposed by a type object is described in the
section :ref:`buffer-structs`, under the description for :c:type:`PyBufferProcs`.
The buffer structure
====================
...
...
Doc/c-api/typeobj.rst
Dosyayı görüntüle @
8abc9358
...
...
@@ -1195,7 +1195,7 @@ Buffer Object Structures
.. sectionauthor:: Benjamin Peterson
The
buffer interface
exports a model where an object can expose its internal
The
:ref:`buffer interface <bufferobjects>`
exports a model where an object can expose its internal
data.
If an object does not export the buffer interface, then its :attr:`tp_as_buffer`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment