CreateFileMapping 以“磁盘空间不足”结束错误
我在理解如何使用 API 函数 CreateFileMapping(...)
时遇到问题。
我一直在尝试映射一个小文件,然后反转它的内容。它只有大约 1 Kb,但我不断收到“内存不足”错误。
我通过调用 CreateFile
打开了该文件,并使用 GetFileSize
获取了它的大小。
然后我打电话:
CreateFileMapping(fileHandle,
NULL,
PAGE_READWRITE | SEC_RESERVE,
fileSize + 1,
fileSize + 1,
NULL);
我怀疑问题在于将 fileSize + 1
作为 dwFileOffsetHigh
和 dwFileOffsetLow
传递,但我很难理解什么我应该转给它吗?
任何提示都非常感谢!
I have a problem understanding how to use the API function CreateFileMapping(...)
.
I've been trying to map a small file and then reverse it's content. It has only about 1 Kb, but I keep getting the "Not enough memory" error.
I have opened the file by calling CreateFile
and got it's size with GetFileSize
.
Then I call:
CreateFileMapping(fileHandle,
NULL,
PAGE_READWRITE | SEC_RESERVE,
fileSize + 1,
fileSize + 1,
NULL);
I suspect that the problem is with passing the fileSize + 1
as dwFileOffsetHigh
and dwFileOffsetLow
, but I have a hard time understanding what should I pass to it instead.
Any hints are greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
dwFileOffsetHigh
和dwFileOffsetLow
是两个 32 位值,它们组合起来形成一个 64 位值。此函数以这种方式实现,因为它早于编译器对 64 位值的广泛支持。我认为你的误解是认为高和低意味着上限和下限。
在您的情况下,您的值(假设
fileSize
约为 1KB)远未需要 64 位,因此您应该为dwFileOffsetLow
和 <代码>0代表dwFileOffsetHigh
。但是,如果您尝试映射整个文件,则只需为两个参数传递
0
即可。来自文档:
dwFileOffsetHigh
anddwFileOffsetLow
are two 32 bit values that are combined to form a single 64 bit value. This function was implemented this way because it pre-dates widespread compiler support for 64 bit values.I think your misunderstanding is in believing that the high and low mean upper and lower limits.
In your case your value (assuming
fileSize
is around 1KB) is nowhere near requiring 64 bits so you should passfileSize+1
fordwFileOffsetLow
and0
fordwFileOffsetHigh
.However, if you are attempting to map the entire file you can simply pass
0
for both parameters.From the documentation:
您正在尝试创建一个非常大的文件映射。
dwFileOffsetHight
和dwFileOffsetLow
是 64 位积分的高位和低位 32 位分量。使用GetFileSizeEx
来获取文件大小的两个组成部分。You are attempting to create a very big file mapping.
dwFileOffsetHight
anddwFileOffsetLow
are the high and low 32 bit components of a 64bit integral. UseGetFileSizeEx
instead to get both components of the file size.