You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After the slice operation, **ob_start** points to the real beginning of the content, and **ob_bytes** still points to the begin address of the malloced block
as long as the slice operation is going to shrink the bytearray, and the **new_size < alloc / 2** is False, the resize operation won't shrink the real mallcoed size
84
+
as long as the slice operation is going to shrink the bytearray, and the **new_size < allocate / 2** is False, the resize operation won't shrink the real malloced size
what's field **ob_exports** mean ? If you need detail, you can refer to [less-copies-in-python-with-the-buffer-protocol-and-memoryviews](https://eli.thegreenplace.net/2011/11/28/less-copies-in-python-with-the-buffer-protocol-and-memoryviews) and [PEP 3118](https://www.python.org/dev/peps/pep-3118/)
the **bytearray** implements the **buffer protocol**, and **memoryview** is able to access the internal data block via the **buffer protocol**, **mybuf** and **buf** are all sharing the same internal block
113
113
114
114
field **ob_exports** becomes 1, which indicate how many objects currently sharing the internal block via **buffer protocol**
so does **mybuf2** object(**ob_exports** doesn't change because you need to call the c function defined by **buf** object via the **buffer protocol**, **mybuf2** barely calls the slice function of **mybuf**)
Copy file name to clipboardExpand all lines: BasicObject/bytes/bytes.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@
5
5
*[related file](#related-file)
6
6
*[memory layout](#memory-layout)
7
7
*[example](#example)
8
-
* [empty bytes](#empty-bytes)
9
-
* [ascii characters](#ascii-characters)
10
-
* [nonascii characters](#nonascii-characters)
8
+
*[empty bytes](#empty-bytes)
9
+
*[ascii characters](#ascii-characters)
10
+
*[nonascii characters](#nonascii-characters)
11
11
*[summary](#summary)
12
-
* [ob_shash](#ob_shash)
13
-
* [ob_size](#ob_size)
14
-
* [summary](#summary)
12
+
*[ob_shash](#ob_shash)
13
+
*[ob_size](#ob_size)
14
+
*[summary](#summary)
15
15
16
16
#### related file
17
17
* cpython/Objects/bytesobject.c
@@ -30,21 +30,21 @@ The memory layout of **PyBytesObject** looks like [memory layout of tuple object
30
30
31
31
**bytes** object is an immutable object, whenever you need to modify a **bytes** object, you need to create a new one, which keeps the implementation simple.
@@ -186,14 +186,14 @@ let's see what's under the hood
186
186
>>> cc.fc1
187
187
<bound method <lambda> of <class '__main__.C'>>
188
188
189
-
get different result when access the same object in different way, why?
189
+
get a different result when access the same object in a different way, why?
190
190
191
-
when you trying to access the **fc1** in instance cc, the **descriptor protocol** will try several different path to get the attribute in the following step
191
+
when you trying to access the **fc1** in instance cc, the **descriptor protocol** will try several different paths to get the attribute in the following step
0 commit comments