The surprising way to save memory with BytesIO

from blog Simon Willison's Weblog, | ↗ original
The surprising way to save memory with BytesIO Itamar Turner-Trauring explains that if you have a BytesIO object in Python calling .read() on it will create a full copy of that object, doubling the amount of memory used - but calling .getvalue() returns a bytes object that uses no additional memory, instead using copy-on-write. .getbuffer() is...