python - 什么时候应该使用内存 View ?

标签 python python-3.x memoryview

memoryview的完整描述可以查看here :

Create a memoryview that references obj. obj must support the buffer protocol. Built-in objects that support the buffer protocol include bytes and bytearray.

A memoryview has the notion of an element, which is the atomic memory unit handled by the originating object obj. For many simple types such as bytes and bytearray, an element is a single byte, but other types such as array.array may have bigger elements.

最佳答案

内存 View 本质上是 Python 本身中的一个通用 NumPy 数组结构(没有数学)。它允许您在数据结构(如 PIL 图像、SQLlite 数据库、NumPy 数组等)之间共享内存,而无需先复制。这对于大型数据集非常重要。

有了它,您可以将内存映射到一个非常大的文件,对该文件进行切片并对该文件进行计算(如果您使用 NumPy 则最简单)。

关于python - 什么时候应该使用内存 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4845418/

相关文章:

python - python 中 a-b ==0 和 a ==b 有什么区别

python - numba - guvectorize 比 jit 快一点

python - python中的矩阵镜像

python - 为什么 Python 3 的常规字符串替换会吞掉字符?

Python:如何将每个负数变成零?

python - 合并两列,忽略空单元格并添加分隔符

python - 使用python中的struct模块打包和解包可变长度数组/字符串

python - Cython:在没有 NumPy 数组的情况下创建内存 View ?

cython - 如果尺寸未知,请在 cython 中使用 Typed memoryview