简体   繁体   English

提升mapping_file_sink抛出异常

[英]boost mapped_file_sink throw exception

I don't know why it throw exception when I create mapped_file_sink object. 我不知道为什么在创建mapled_file_sink对象时会引发异常。

Exception: 例外:

terminate called after throwing an instance of 
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::exception> >'
int main(int argc,char *argv[])
{
        boost::iostreams::mapped_file_sink sink(argv[1]);
        char temp[] ="AAAA";
        memcpy(sink.data(), temp, sizeof(temp));
        sink.close();
        return 1;
}

Most likely file AAAA doesn't exist. 很可能文件AAAA不存在。 In order to create the file you need to open memory-mapped file using boost::iostreams::mapped_file_params variable whose new_file_size field would be set to desirable size of file. 为了创建文件,您需要使用boost::iostreams::mapped_file_params变量打开内存映射文件,该变量的new_file_size字段将设置为所需的文件大小。

With boost 1.53 in a 64 bit Linux virtual machine, I too encountered the exception reported above. 在64位Linux虚拟机中使用boost 1.53时,我也遇到了上面报告的异常。

I eventually tracked it down to a permission problem. 我最终找到了权限问题。 When I ran my test from a virtual box share folder I could create the and size file, but I would get the mystery exception when BOOST_IOSTREAMS_FD_MMAP failed calling cleanup_and_throw("failed mapping file"). 当我从虚拟盒子共享文件夹运行测试时,我可以创建和大小文件,但是当BOOST_IOSTREAMS_FD_MMAP调用cleanup_and_throw(“失败的映射文件”)失败时,我将得到一个神秘的异常。

Somewhere along the way in the throw enable_current_exception(enable_error_info(e)); 抛出过程中的某个地方enable_current_exception(enable_error_info(e)); call the "failed mapping file: invalid argument" message is lost. 调用“失败的映射文件:无效参数”消息丢失。

If the same code were run from my home folder the api works as expected. 如果从我的主文件夹中运行了相同的代码,则api会按预期工作。

So the essence of my problem came down to permissions. 因此,我的问题的实质在于权限。 I hope this helps anyone else who encounters this. 希望这对遇到此问题的其他人有所帮助。

drwxrwx--- root vboxsf drwxrwx ---根vboxsf

vs

drwxr-xr-x user user drwxr-xr-x用户用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM