- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在理解如何使用 API 函数 CreateFileMapping(...)
时遇到问题。
我一直在尝试映射一个小文件,然后反转它的内容。它只有大约 1 Kb,但我一直收到“内存不足”错误。
我已通过调用 CreateFile
打开了文件,并使用 GetFileSize
获取了它的大小。
然后我调用:
CreateFileMapping(fileHandle,
NULL,
PAGE_READWRITE | SEC_RESERVE,
fileSize + 1,
fileSize + 1,
NULL);
我怀疑问题是将 fileSize + 1
作为 dwFileOffsetHigh
和 dwFileOffsetLow
传递,但我很难理解应该做什么我改为传递给它。
非常感谢任何提示!
最佳答案
dwFileOffsetHigh
和 dwFileOffsetLow
是两个 32 位值,它们组合形成一个 64 位值。此函数以这种方式实现,因为它早于编译器对 64 位值的广泛支持。
我觉得你的误区是认为high和low就是上下限。
在您的情况下,您的值(假设 fileSize
约为 1KB)远不及需要 64 位,因此您应该为 dwFileOffsetLow
通过 fileSize+1
> 和 0
用于 dwFileOffsetHigh
。
但是,如果您尝试映射整个文件,您可以简单地为两个参数传递 0
。
来自documentation :
dwMaximumSizeHigh [in]
The high-order DWORD of the maximum size of the file mapping object.
dwMaximumSizeLow [in]
The low-order DWORD of the maximum size of the file mapping object.
If this parameter and dwMaximumSizeHigh are 0 (zero), the maximum size of the file mapping object is equal to the current size of the file that hFile identifies.
An attempt to map a file with a length of 0 (zero) fails with an error code of ERROR_FILE_INVALID. Applications should test for files with a length of 0 (zero) and reject those files.
关于CreateFileMapping 以 "Not enough disk space"错误结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7799914/
我是一名优秀的程序员,十分优秀!