Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

Py_buffer is often used for handling arguments if the function supports bytes, 
bytearray and other bytes-like objects. For example bytes.partition(). Any 
additional memory allocation would add significant overhead here. bytes.join() 
creates Py_buffer for every item, it would be a deoptimization if it would need 
to allocate them all separately.

We should allow to allocate Py_buffer on stack. Currently it has too complex 
structure and we cannot guarantee its stability (although there were no changes 
for years). I propose to split Py_buffer on transparent and opaque parts and 
standardize the transparent structure. It should include: obj, buf, len, 
possible flags (to distinguish read-only from writeable) and a pointer to 
opaque data. For bytes, bytearray, BytesIO, mmap and most other classes the 
pointer to opaque data is NULL. For array and memoryview objects the opaque 
data could be embedded into the object.

----------
nosy: +skrah

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45459>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to