When should a memoryview be used? [duplicate] When should a memoryview be used? [duplicate] python python

When should a memoryview be used? [duplicate]


A memoryview is essentially a generalized NumPy array structure in Python itself (without the math). It allows you to share memory between data-structures (things like PIL images, SQLlite data-bases, NumPy arrays, etc.) without first copying. This is very important for large data sets.

With it you can do things like memory-map to a very large file, slice a piece of that file and do calculations on that piece (easiest if you are using NumPy).


From the documentation, I figure it's used to "access the internal data of an object that supports the buffer protocol without copying", so you can do things with huge chunks of data without filling up your memory. I don't know if you want examples, but I can't think of any, unfortunately.