我已经阅读了一些相关内容boost::interprocess::file_lock,它似乎做了我想要做的事情(支持共享和独占锁定,并在进程崩溃或退出时解锁)。
但我不确定的一件事是它对文件有什么作用?例如,我可以使用 0 字节长的文件吗?boost::interprocess里面写东西吗?或者系统只关心它的存在吗?
我现在已经使用了boost::interprocess一段时间来可靠地内存映射文件并写入文件,现在我需要进行多进程并确保对此文件的读取和写入受到保护;file_lock似乎是可行的方法,我只是想知道我现在是否需要添加另一个文件来用作互斥体。
提前致谢
我很难理解为什么下面的代码没有警告:
unsigned test = 0xffffffff;
for (unsigned char i = 0; i < test; i++)
{
// Some code
}
Run Code Online (Sandbox Code Playgroud)
这是在Visual Studio 2010上,但GCC显然也没有警告.谁知道为什么?
我最近尝试通过 Boost log 将一些日志记录添加到一个小型应用程序中。但是,使用日志轮换,由于某种原因,我无法让它在日志目录中拾取正确的计数器。
例如,如果我的Logs目录包含文件Log_000.log并且Log_001.log我希望日志记录以Log_002.log,但它总是从 0 开始。
我可能错过了一些东西,但如果有人能发现一些东西,我将不胜感激。这是我的启动代码:
void initLogging()
{
boost::log::add_common_attributes();
auto core = boost::log::core::get();
core->add_global_attribute("UTCTimeStamp",boost::log::attributes::utc_clock());
auto x = boost::log::add_file_log(
boost::log::keywords::file_name = "Log_%3N.log",
boost::log::keywords::rotation_size = 2 * 1024, // 2k
boost::log::keywords::target = "Logs",
boost::log::keywords::min_free_space = 30 * 1024 * 1024,
boost::log::keywords::max_size = 20 * 1024, // 20k
boost::log::keywords::time_based_rotation = boost::log::sinks::file::rotation_at_time_point(boost::gregorian::greg_day(31)),
boost::log::keywords::scan_method = boost::log::sinks::file::scan_matching,
boost::log::keywords::format = "%UTCTimeStamp% (%TimeStamp%) [%ThreadID%]: %Message%",
boost::log::keywords::auto_flush = true
);
auto d = x->locked_backend()->scan_for_files();
}
Run Code Online (Sandbox Code Playgroud)
非常感谢
只需看看Sublime Text 2就可以扩展它.我用CTRL'弹出控制台,试图做:
>>> x = window.new_file()
>>> x
<sublime.View object at 0x00000000032EBA70>
>>> x.insert(0,"Hello")
Run Code Online (Sandbox Code Playgroud)
确实打开了一个新窗口但是我的插件看起来不起作用:
Traceback (most recent call last): File "<string>", line 1, in <module> Boost.Python.ArgumentError: Python argument types in
View.insert(View, int, str) did not match C++ signature:
insert(class SP<class TextBufferView>, class SP<class Edit>, __int64, class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?