C++
共 5 篇文章
message queue常见操作和例子
message queue是System V IPC中的三剑客之一(分别是message queue, semaphore, shared memory),其主要是由下面4个函数调用构成: (msgget, msgctl, msgsnd, msgrcv),下面列举出具体的应用,以作备份 (1) msgsend.cxx (创建message queue, 并且发送message到内核的消息队列里面) #include<sys/types.h> #include<sys/ipc.h> #include<sys/msg.h> #include<string.h> #include<stdio.h>…
2009-04-23 00:11 · C++
boost::bind使用例子
#include <iostream> #include <list> #include <vector> #include <algorithm> #include <iterator> #include <boost/bind.hpp> using namespace std; void composite1() { list<double> l; l.push_back(1.0); l.push_back(10.0); l.push_back(100.0); l.push_back(1000.0); cout<<"Before transformation"<<endl; copy(l…
2009-04-11 22:32 · C++
boost::bind基本应用
boost::bind功能强大,可以很好的实现对函数,函数对象之类的进行绑定 下面是一个具体的例子 #include <iostream> #include <string> #include <vector> #include <algorithm> #include <boost/bind.hpp> using namespace std; class Person { public: Person(string name) { name_ = name; } void doit() { cout<<"I am "<<name_<<endl; } private: string name…
2009-04-11 14:52 · C++ · C · C++ · C#
C++中的智能指针 smart_ptr
在 C++ 中需要自己来处理内存,稍微处理不当,就会存在非常郁闷的内存泄漏问题 还好,现在 C++ 中推出了强大的智能指针,即 smart_ptr ,本文先稍微介绍一下 smart_ptr ,然后具体说说 shared_ptr 和 weak_ptr ,特别是 enable_shared_from_this 和 shared_from_this 除了标准库中的 auto_ptr 之外 在 boost 或者 tr1 中的 smart_ptr 主要是有下面几种 scoped_ptr scoped_array shared_ptr shared_array intrusive_ptr weak_pt…
2009-04-09 23:57 · C++ · C · C++ · Blog · C#
ptr_fun学习笔记
ptr_fun是将一个普通的函数适配成一个functor,添加上argument type和result type等类型, 其实现如下(例子里面是binary_function,unary_function同理): [code="c++"] template inline pointer_to_binary_function<_Arg1, _Arg2, _Result, _Result(__fastcall *)(_Arg1, _Arg2)> ptr_fun(_Result (__fastcall *_Left)(_Arg1, _Arg2)) { // return pointer_to_b…
2009-02-20 23:38 · C++ · C · 算法 · C++ · C#