[Python-Dev] bytes with trailing \0?

Nikolaus Rath Nikolaus at rath.org
Tue Apr 29 05:48:11 CEST 2014


Hello,

I was surprised to find the following in bytesobject.c:

,----
| [...]
|    As always, an extra byte is allocated for a trailing \0 byte (newsize
|    does *not* include that), and a trailing \0 byte is stored.
| */
| 
| int
| _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
| {
| [...]
| 
`----

Does this mean that bytes objects are internally stored with a trailing
\0? Why is that? Isn't that just wasting a byte, because \0 might also
be in the middle of the byte sequence, and the bytes objects stores its
length explicitly anyway?


Best,
-Nikolaus
-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«


More information about the Python-Dev mailing list