草庐IT

boost-pool

全部标签

c++ - 努力获得 boost 共享内存段来构建

我有一些代码正在尝试创建一个共享内存段。为此,该段是从一个类中管理的。共享部分将以“公告板”方式使用。也就是说,这个进程将写入它,而许多其他进程将从中读取。事不宜迟:#include#include#includestaticconststd::stringSHM_NAME("SharedMemory");staticconststd::stringSHM_STATUS("StatusArray");staticconststd::stringSHM_INFO1("MfgData");classManager{u_int8_t*_status;char*_info;boost::int

C++11 替代 boost::checked_delete

作为前向声明的重度用户,我喜欢我的类在销毁时完成。为确保这一点,我将析构函数设为私有(private)并与boost::checked_delete成为friend:#includestructMyClass{//MyClass'sinterfaceprivate:~MyClass(){/*something*/}friendvoidboost::checked_delete(MyClass*x);};在C++11中,std::default_delete还在销毁时检查完整性。然而,我无法实现与上面相同的行为:#includestructMyClass{//MyClass'sinter

c++ - 在非 boost 线程中使用 boost::thread_specific_ptr

我正在阅读thedocumentationsectionforboost::thread_specific_ptr,并尝试解析这段:Note:onsomeplatforms,cleanupofthread-specificdataisnotperformedforthreadscreatedwiththeplatform'snativeAPI.Onthoseplatformssuchcleanupisonlydoneforthreadsthatarestartedwithboost::threadunlessboost::on_thread_exit()iscalledmanually

c++ - boost 单位的平方根 scaled_unit

我使用boost::units来处理项目中的单元。我创建了一个缩放单位来存储微米:usingnamespaceboost::units;typedefmake_scaled_unit>>::typemicro_meter_unit;一切如期进行:quantitysome_meter=10*si::meter;quantitysome_mu_meter=static_cast>(some_meter);std::cout但是平方根运算没有被编译:std::cout'beingcompiled//with//[//X=boost::units::quantity,//Y=boost::un

c++ - boost线程库的型号是什么

c++boost线程库使用的线程模型是什么?1:1(内核级线程)N:1(用户级线程)M:N(混合线程)这些模型之间的区别(来自wiki):http://en.wikipedia.org/wiki/Thread_(computing)#Models我检查了boost站点,它没有提到它使用的线程模型。我猜是1:1,因为它没有提供yield或reschedule之类的功能,但我不确定... 最佳答案 它是native线程,即它会使用平台线程,至少在Linux、Windows和Mac中是这样。据我所知,对于每个生成的线程,线程映射将与Win

c++ - 使用 Boost 就地替换正则表达式

我有一大段文本存储在名为“text”的std::string中。在这个字符串上,我使用boostregex库将某些模式替换为空格。这是我的代码。//Removetimesoftheform(00:33)and(1:33)boost::regexrgx("\\([0-9.:]*\\)");text=boost::regex_replace(text,rgx,"");//RemovesinglewordHTMLtagsrgx.set_expression("");text=boost::regex_replace(text,rgx,"");//Removecommentslike[paus

c++ 内存泄漏 - boost 库

我在以下程序中观察到内存泄漏://g++-std=c++1132_MyTime.cpp////valgrind--leak-check=full./a.out//#include#includeusingnamespacestd;classMyTime{private:intyear;intmonth;intday;inthour;boost::posix_time::ptime*ptrTime;voidupdate(){year=ptrTime->date().year();month=ptrTime->date().month();day=ptrTime->date().day()

c++ - 与 static_assert 和 boost::hana 相关的 Clang 编译错误

考虑以下使用-std=c++14在Clang3.8上成功编译的问题。#includenamespacehana=boost::hana;intmain(){constexprautoindices=hana::range();hana::for_each(indices,[&](autoi){hana::for_each(indices,[&](autoj){constexprbooltest=(i==(j==i?j:i));static_assert(test,"error");});});}这个测试非常荒谬,但这不是重点。现在考虑一个替代版本,其中测试直接放在static_asse

c++ - 刷新 boost::iostreams::zlib_compressor。如何获得 "sync flush"?

获得"zlibsyncflush"需要一些魔法吗?使用boost::iostreams::zlib_compressor时?只是在过滤器上调用flush,或者在包含它的filtering_ostream上调用strict_sync并不能完成这项工作(即我希望压缩器冲洗足够多,解压缩器可以恢复压缩器到目前为止消耗的所有字节,而无需关闭流)。查看header,似乎定义了一些“刷新代码”(特别是sync_flush),但我不清楚它们应该如何使用(记住我的压缩器刚刚添加到filtering_ostream)。 最佳答案 事实证明,symme

c++ - 需要解释这个 boost::asio 计时器示例

在Boostasio的第3教程中有一行显示了如何更新计时器并防止其漂移。该行如下:t->expires_at(t->expires_at()+boost::posix_time::seconds(1));也许是我的问题,但我找不到关于expires_at()第二次使用的文档,没有参数。expires_at(x)设置新的到期时间,取消任何未决的完成处理程序。所以大概expires_at()做了什么,最后一次到期的返回时间?因此,通过增加一秒,如果应该有一定数量的毫秒,比如n毫秒,那么它实际上会从下一个到期时间中“减去”,因为时间正在计算中?如果在此示例中执行此处理程序所需的时间大于1秒,