在Windows上使用Python可以通过以下方式创建一个大文件:
from mmap import mmap
f = open('big.file', 'w')
f.close()
f = open('big.file', 'r+')
m = mmap(f.fileno(), 10**9)
现在big.file
的大小约为1GB。但是在Linux上,这将返回ValueError: mmap length is greater than file size
。
有没有一种方法可以在Linux上像Windows一样实现相同的行为?也就是说,能够使用mmap
增加文件的大小吗?