Search code examples
pythonpython-3.xloopsskipenumerate

When/how is the "memoryview()" function used?


I came across it in my autocomplete when I started typing the name of a variable that began with m, what is it used for and when/how should it be used?


Solution

  • memoryview() exposes the buffer protocal of an object. Buffers are internal memory arrays. You can use memoryview() to access large pieces of data without having to copy the data, which can be memory-intensive.

    Edit: To further explain, when you know the memory address of an object, you can simply set another object equal to that memory address