gpt4 book ai didi

CreateFileMapping 以 "Not enough disk space"错误结束

转载 作者:可可西里 更新时间:2023-11-01 09:17:39 25 4
gpt4 key购买 nike

我在理解如何使用 API 函数 CreateFileMapping(...) 时遇到问题。

我一直在尝试映射一个小文件,然后反转它的内容。它只有大约 1 Kb,但我一直收到“内存不足”错误。

我已通过调用 CreateFile 打开了文件,并使用 GetFileSize 获取了它的大小。

然后我调用:

CreateFileMapping(fileHandle, 
NULL,
PAGE_READWRITE | SEC_RESERVE,
fileSize + 1,
fileSize + 1,
NULL);

我怀疑问题是将 fileSize + 1 作为 dwFileOffsetHighdwFileOffsetLow 传递,但我很难理解应该做什么我改为传递给它。

非常感谢任何提示!

最佳答案

dwFileOffsetHighdwFileOffsetLow 是两个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com