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
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
102
+
As long as the slice operation is going to shrink the bytearray and **new_size < allocate / 2** is False, the resize operation won't shrink the actual malloced size
now, in the shrink operation, the **new_size < allocate / 2** is True, the resize operation will be triggered
111
+
Now, in the shrink operation, **new_size < allocate / 2** is True, so the resize operation will be triggered
112
112
113
113
```python3
114
114
b[0:3] = [7,8]
@@ -119,7 +119,7 @@ b[0:3] = [7,8]
119
119
120
120
The growing pattern in slice operation is the same as the append operation
121
121
122
-
request size is 6, 6 < 6 * 1.125, so new allocated size is 6 + (6 >> 3) + 3 ==> 9
122
+
The requested size is 6. Since 6 < 6 * 1.125, the new allocated size is 6 + (6 >> 3) + 3 ==> 9
123
123
124
124
```python3
125
125
b[0:3] = [1,2,3,4]
@@ -130,7 +130,7 @@ b[0:3] = [1,2,3,4]
130
130
131
131
## ob_exports
132
132
133
-
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/)
133
+
What does the field **ob_exports** mean? If you need details, 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
142
+
The**bytearray** implements the **buffer protocol**, and **memoryview** is able to access the internal data block via the **buffer protocol**.**mybuf** and **buf**both share the same internal block.
143
143
144
-
field **ob_exports** becomes 1, which indicate how many objects currently sharing the internal block via **buffer protocol**
144
+
The field **ob_exports** becomes 1, which indicates how many objects are currently sharing the internal block via the**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**)
154
+
The same applies to the **mybuf2** object(**ob_exports** doesn't change because you need to call the C function defined by the **buf** object via the **buffer protocol**;**mybuf2**only calls the slice function of **mybuf**)
Copy file name to clipboardExpand all lines: BasicObject/bytes/bytes.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ s = b""
39
39
40
40
## ascii characters
41
41
42
-
let's initialize a byte object with ascii characters
42
+
Let's initialize a bytes object with ASCII characters
43
43
44
44
```python3
45
45
s =b"abcdefg123"
@@ -65,17 +65,17 @@ s = "我是帅哥".encode("utf8")
65
65
66
66
The field **ob_shash** should store the hash value of the byte object, value **-1** means not computed yet.
67
67
68
-
The first time the hash value computed, it will be cached in the **ob_shash** field
68
+
The first time the hash value is computed, it will be cached in the **ob_shash** field.
69
69
70
-
the cached hash value can save recalculation and speeds up dictionary lookups
70
+
The cached hash value can save recalculation and speed up dictionary lookups
71
71
72
72
## ob_size
73
73
74
-
field **ob_size** is inside every **PyVarObject**, the **PyBytesObject** uses this **field** to store size information to keep O(1) time complexity for **len()** operation and tracks the size of non-ascii string(may be null characters inside)
74
+
The field **ob_size** is inside every **PyVarObject**. **PyBytesObject** uses this field to store size information to keep O(1) time complexity for the **len()** operation and to track the size of non-ASCII strings (which may contain null characters inside)
75
75
76
76
## summary
77
77
78
-
The **PyBytesObject** is a python wrapper of c style null terminate string, with **ob_shash** for caching hash value and **ob_size** for storing the size information of **PyBytesObject**
78
+
The **PyBytesObject** is a Python wrapper of C-style null-terminated strings, with **ob_shash** for caching the hash value and **ob_size** for storing size information
79
79
80
80
The implementation of **PyBytesObject** looks like the **embstr** encoding in redis
get a different result when access the same object in a different way, why?
231
+
We get a different result when accessing the same object in a different way. Why?
232
232
233
-
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
233
+
When you try to access **fc1** in instance cc, the **descriptor protocol** will try several different paths to get the attribute in the following steps
@@ -246,7 +246,7 @@ for more detail, please refer to this blog [object-attribute-lookup](https://blo
246
246
247
247
because **classmethod** implements `__get__` and `__set__`, it's a data descriptor, when you try to access attribute **cc.fc1**, you will actually call `fc1.__get__`, and caller will get whatever it returns
248
248
249
-
we can see the `__get__` function of classmethod object(defined as `cm_descr_get` in C)
249
+
We can see the `__get__` function of the classmethod object(defined as `cm_descr_get` in C)
when you access fc1 by **cc.fc1**, the **descriptor protocol** will call the function above, which returns whatever in the **cm_callable**, wrapped by **PyMethod_New()** function, which makes the return object a new bounded-PyMethodObject
271
+
When you access fc1 via **cc.fc1**, the **descriptor protocol** will call the function above, which returns whatever is in **cm_callable**, wrapped by the **PyMethod_New()** function, which makes the returned object a new bound PyMethodObject
Copy file name to clipboardExpand all lines: BasicObject/complex/complex.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,9 @@
13
13
14
14
# memory layout
15
15
16
-
the **PyComplexObject** stores two doubleprecision floatingpoint number inside
16
+
**PyComplexObject** stores two double-precision floating-point numbers inside.
17
17
18
-
the handling process and representation are mostly the same as [float](https://github.com/zpoint/CPython-Internals/blob/master/BasicObject/float/float.md) object
18
+
The handling process and representation are mostly the same as the[float](https://github.com/zpoint/CPython-Internals/blob/master/BasicObject/float/float.md) object
0 commit comments