Boost mapped_file_sink抛出异常
boost mapped_file_sink throw exception
我不知道为什么当我创建mapped_file_sink对象时抛出异常。
异常: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;
}
很可能文件AAAA
不存在。为了创建文件,您需要使用boost::iostreams::mapped_file_params
变量打开内存映射文件,其new_file_size
字段将设置为所需的文件大小。
在64位Linux虚拟机上使用boost 1.53,我也遇到了上面报告的异常。
我最终发现是权限问题。当我从虚拟盒共享文件夹运行我的测试时,我可以创建和大小文件,但是当BOOST_IOSTREAMS_FD_MMAP调用cleanup_and_throw("失败的映射文件")失败时,我会得到神秘的异常。
在抛出enable_current_exception(enable_error_info(e));调用"failed mapping file: invalid argument"消息丢失。
如果从我的主文件夹运行相同的代码,api将按预期工作。
所以我的问题的本质归结为权限。我希望这能帮助到其他遇到这种情况的人。
drwxrwx——root vboxsf
和
drwxr-xr-x user user
相关文章:
- 从构造函数抛出异常时如何克服内存泄漏
- 函数如何通知用户它基于函数原型抛出异常?
- 在缺少函数重载时抛出异常,并带有 std::variant 而不是编译时错误
- VisualStudios 会抛出异常,而代码块不会 [C++]
- 如果不包含 pthread,为什么 GCC 的线程标准库实现会抛出异常?
- ZMQ::send() 抛出异常并终止 QNX 进程.为什么以及如何从中恢复?
- new(std::nothrow) int[n] 抛出异常
- 为什么g_object_set抛出异常(vcruntime140.dll)?
- 你能防止 std::regex 在无效表达式上抛出异常吗?
- C++子线程抛出异常
- 我们应该在抛出异常之前取消分配内存吗
- 有没有一种方法可以让OpenCLC++绑定为所有错误抛出异常
- 为什么访问模板化变体作为返回值抛出异常
- 如何实现,错误分配中止而不是抛出异常
- std::p riority_queue::p op什么时候会抛出异常
- 在0x5914F3BE抛出异常(基于.dll)
- std::vector 默认构造函数可以抛出异常吗?
- 挂钩创建文件抛出异常:读取访问冲突
- getaddrinfo 抛出异常
- 如果文件为c ,如何抛出异常