我在 x32 win xp 上使用 python x32
有时程序在线失败
fp = np.memmap('C:/memmap_test', dtype='float32', mode='w+', shape=(rows,cols))
错误memmap.py
Traceback (most recent call last):
fp = np.memmap('C:/memmap_test', dtype='float32', mode='w+', shape=(rows,cols)) File "C:\Python27\lib\site-packages\numpy\core\memmap.py", line 253, in __new__
mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
OverflowError: cannot fit 'long' into an index-sized integer
所以我假设数组的大小有限制,那么数组 maxN = rows*cols 的最大大小是多少?
1. python x32 win x64 和 2. python x64 win x64 也是相同的问题。
更新:
#create array
rows= 250000
cols= 1000
fA= np.memmap('A.npy', dtype='float32', mode='w+', shape=(rows,cols))
# fA1= np.memmap('A1.npy', dtype='float32', mode='w+', shape=(rows,cols)) # can't create another one big memmap
print fA.nbytes/1024/1024 # 953 mb
所以似乎还有另一个限制,不仅对于单个内存映射数组 <2Gb。
还输出@Paul 提供的测试
working with 30000000 elements
number bytes required 0.240000 GB
works
working with 300000000 elements
number bytes required 2.400000 GB
OverflowError("cannot fit 'long' into an index-sized integer",)
working with 3000000000 elements
number bytes required 24.000000 GB
IOError(28, 'No space left on device')
working with 30000000000 elements
number bytes required 240.000000 GB
IOError(28, 'No space left on device')
working with 300000000000 elements
number bytes required 2400.000000 GB
IOError(28, 'No space left on device')
working with 3000000000000 elements
number bytes required 24000.000000 GB
IOError(22, 'Invalid argument')