boost.smart_ptr库提供了六种智能指针:scoped_ptr、scoped_array、shared_ptr、shared_array、week_ptr和intrusive_ptr。
说到智能指针,我们会想到c++98标准中的自动指针auto_ptr.auto_ptr获取指针所有权后,离开作用域时自动释放该指针指向的堆内存。也可以转移指针的所有权。
auto_ptr ap_a1(new...
分类:
其他好文 时间:
2015-01-30 21:08:29
阅读次数:
364
C++ 编写一个不可复制的类
flyfish
Effective C++:条款06
若不想使用编译器自动生成的函数,就该明确拒绝 .
Explicitly disallow the use of complier-generated functions you do not want.
老式C++的写法
class noncopyable
{
protected:
nonco...
分类:
编程语言 时间:
2015-01-30 16:04:54
阅读次数:
185
编程时候经常需要使用定长的容器(fixed size container),比如有时日志只需要保留一周或一个月,或者缓存一天上游发来的数据流。实现一个简单的旋转容器只需要像下面这样就好:std::vector vec(size);vec[i % size] = newelem;boost的circu...
分类:
其他好文 时间:
2015-01-29 14:20:20
阅读次数:
150
std::auto_ptr很多的时候并不能满足我们的要求,比如auto_ptr不能用作STL容器的元素。boost的smart_ptr中提供了4种智能指针和2种智能指针数组来作为std::auto_ptr的补充。
shared_ptr:使用shared_ptr进行对象的生存期自动管理,使得分享资源所有权变得有效且安全.
weak_ptr:weak_ptr 是 shared_ptr 的观察员...
分类:
其他好文 时间:
2015-01-29 09:22:31
阅读次数:
288
1 unzip boost_1_57_0.zip2 ./bootstrap.sh3 ./b2 toolset=gcc cxxflags="-std=c++11" install4 find / -name libboost*.a/usr/local/lib目录下头文件在/usr/local/incl...
分类:
系统相关 时间:
2015-01-28 17:42:40
阅读次数:
1325
(1)ACE庞大、复杂,适合大型项目。开源、免费,不依赖第三方库,支持跨平台。http://www.cs.wustl.edu/~schmidt/ACE.html(2)AsioAsio基于Boost开发的异步IO库,封装了Socket,简化基于socket程序的开发。开源、免费,支持跨平台。http:...
分类:
编程语言 时间:
2015-01-28 17:31:28
阅读次数:
189
#include #include #include #include #include #include using namespace std; using namespace boost; //写一个程序,提取之间的内容 ...
分类:
其他好文 时间:
2015-01-28 17:24:44
阅读次数:
200
看一个别人给出的例子,当我们输入“select 字符串 from 字符串”的时候,会得到输出;如果不符合这个格式,就会输出error。注意:在命令行下输入的时候,按ctrl+Z、回车表示行输入结束。 #include #include #include #include...
分类:
其他好文 时间:
2015-01-28 17:17:42
阅读次数:
187
一种是用boost::atomic;一种直接加锁;代码很简单:
#include
#include
#include
#include
#include
#include
#include
#include
static int loop_num = 10000;
boost::atomic a(0);
static boost::mutex mtx_;
static v...
分类:
系统相关 时间:
2015-01-28 01:01:01
阅读次数:
352
如果你是偶然浏览到这里,请先看源代码及例程下载地址:命令行:svn checkout http://st-asio-wrapper.googlecode.com/svn/trunk/ st-asio-wrapper-read-only如果从svn客户端界面上打开,则只输入http://st-asio...
分类:
移动开发 时间:
2015-01-28 00:56:32
阅读次数:
327