提高:: iostreams的:: mapped_file_source ::开放的原因退出码3在Windows,但在Ubuntu工程

问题描述 投票:0回答:1

我使用mapped_file_sourceboost::iostreams namespace从块大文件读取:

boost::iostreams::mapped_file_source read_bytes(const char *file_path,
                                                unsigned long long int offset,
                                                unsigned long long int length) {
    iostreams::mapped_file_params parameters;
    parameters.path = file_path;
    parameters.length = static_cast<size_t>(length);
    parameters.flags = iostreams::mapped_file::mapmode::readonly;
    parameters.offset = static_cast<boost::iostreams::stream_offset>(offset);

    boost::iostreams::mapped_file_source file;

    file.open(parameters);

    if (file.is_open()) {
        return file;
    } else {
        printf("Failed to open file\n");
        exit(EXIT_FAILURE);
    }
}

我的代码工作正常,在Ubuntu WSLWindows Subsystem for Linux),但是当我编译和运行在Windows上它,第二file.open调用导致程序退出码3退出。

Reading file in 5 parts
Processing chunk 1/5
Processing chunk 2/5

Process finished with exit code 3

没有错误消息或异常已经引起。该documentation表明,它是ERROR_PATH_NOT_FOUND但没有任何意义。

我调试两个平台的二进制文件和所有的变量都具有唯一的例外是在Unix风格的文件路径和Windows风格的路径以及分配的地址和系统时间变量,所以没有内存损坏发生完全相同。我不明白为什么这不会对Windows工作时,它应该表现相同。

我使用MinGW编译为Windows gcc 8.2Ubuntu

"C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\x86_64-w64-mingw32-gcc.exe" --version
x86_64-w64-mingw32-gcc.exe (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

如果我在一个单一的去读取这个文件,它工作正常(!)。我对齐所有偏移到页面大小的倍数。当它超出范围,所以它不是一个“文件已打开”的问题(这将导致实际由mapped_file_source除外)的Boost自动关闭。

c++ windows boost mingw memory-mapped-files
1个回答
0
投票

使用MSVC问题不能再被复制现在。在一般情况下,使用Microsoft的编译器Windows可能比MinGW的喜欢更可靠,尤其是因为我是用an "unofficial" toolchain

© www.soinside.com 2019 - 2024. All rights reserved.