0

我刚开始使用 Application Verifier (10.0,x64) 来调试一些潜在的内存问题,但现在我遇到了几个以前从未出现过的奇怪问题。

例如,当我调用MapViewOfFile()小于 400KB 的文件时,我得到了 return value 8,我相信是ERROR_NOT_ENOUGH_MEMORY. 引发错误的特定文件似乎是随机变化的,有时根本不会引发错误。HEAP我已将 Application Verifier选项缩小到BASIC. 必须启用此选项才能引发错误。在使用 Application Verifier 之前,我从未遇到过与此相关代码相关的任何问题。

这是否指向我的代码某处的问题,或者这是某种类型的不兼容?这就是我试图回答的问题。

这是我的功能。我意识到这个小片段并没有提供太多细节,所以如果你想看一些具体的东西,请告诉我。我只使用这个函数来映射整个文件。到目前为止,所有抛出错误的文件都是纹理 PNG 图像。这可能是因为所有其他文件相比之下都很小。

Bool streamMap::OpenHandles() // Opens file handles
{
    // verify
    _VE( FilePtr == null && Offset == 0 && HXFile == INVALID_HANDLE_VALUE, "Invalid starting state. File may already be open. Cannot open another file with the same file interface object" );

    // create the File handle
    // + note: CreateFile macro is undefined by Kestarda, so we use actual function CreateFileA
    HXFile = CreateFileA( FullPath,
                    GENERIC_READ,           // open for reading
                    FILE_SHARE_READ,        // share for reading
                    null,                   // no security 
                    OPEN_EXISTING,          // existing file only 
                    FILE_ATTRIBUTE_NORMAL,  // normal file 
                    null);                  // no attribute template

    // check for failure
    if( HXFile == INVALID_HANDLE_VALUE )
        return false;

    // create Mapping
    // + we use 0 for dwMaximumSizeHigh & dwMaximumSizeLow to specify the entire file (supplied by HXFile)
    HXMap = CreateFileMapping( HXFile, 0, PAGE_READONLY, 0, 0, null );
    if( HXMap == null )
    {
        // close the file handle and return false
        CloseHandle( HXFile );
        HXFile = INVALID_HANDLE_VALUE;
        return false;
    }

    // get map view of file
    FilePtr = reinterpret_cast<byte*>( MapViewOfFile( HXMap, FILE_MAP_READ,0,0,0 ) );
    if( FilePtr == null )
    {
        // close both handles and return false
        CloseHandle(HXMap);
        CloseHandle(HXFile);

        HXMap = null;
        HXFile = INVALID_HANDLE_VALUE;
        return false;
    }

    // success
    return true;
}

是否有人对 Application Verifier(及其选项)足够熟悉,HEAP可以帮助我弄清楚为什么会发生这种情况?

4

0 回答 0