auz*_*uzn 4 python numpy numpy-memmap
在 64 位 Windows 机器上的典型调用过程中numpy.memmap()
,python 会引发以下错误:
OSError: [WinError 8] Not enough memory resources are available to process this command
Run Code Online (Sandbox Code Playgroud)
不同的 Windows 机器会用不同的文本引发相同的错误:
OSError: [WinError 8] Not enough storage is available to process this command.
Run Code Online (Sandbox Code Playgroud)
这是代码摘要:
with open(infile, 'rb') as f:
......
array = numpy.memmap(f, dtype='uint8', mode='r', offset=offset, shape=arraysize).tolist()
Run Code Online (Sandbox Code Playgroud)
此时Python仅使用了50MB的内存。内存不足的原因是什么?
事实证明,这里的问题是memmap 调用中的offset
+shape
大于文件的总大小(即我试图读取超出文件大小的内容)。
在这种情况下,有关内存资源的错误消息有点误导。