Python memoryview() Function
Returns a memory view of an object.
||Required. The object for which the memoryview will be created.|
memoryview allows Python code to
access the internal data of an object without
copying the data first, which can be a significant performance improvement.
Working on binary data in a large image is a good example, where we don't want
to create a copy of the entire image to manipulate its pixels. The object
must support the buffer protocol.
Built-in objects that support the buffer protocol include
bytearray. Other objects that support the buffer protocol
include the Python Image Library (PIL), NumPy arrays, SQLlite databases.
myByteArray = bytearray('ABC', 'utf-8') view = memoryview(myByteArray) print(myByteArray) view = 97 # lowercase a view = 98 # lowercase b view = 99 # lowercase c print(myByteArray)