随笔分类 - c++
摘要:在传统的操作系统中,进程拥有独立的内存地址空间和一个用于控制的线程。但是,现在的情况更多的情况下要求在同一地址空间下拥有多个线程并发执行。因此线程被引入操作系统。为什么需要线程? 如果非要说是为什么需要线程,还不如说为什么需要进程中还有其它进程。这些进程中包含的其它迷你进程就是线程。 线程之所以说是...
阅读全文
摘要:#include #include #include #include int producer_count = 0;boost::atomic_int consumer_count (0);boost::lockfree::spsc_queue > spsc_queue;//但生产者但消费者队列,...
阅读全文
摘要:resize改变的实际的大小,reserve是容量即capacity如果先指定capacity的大小,可以防止内存的重新分配,我感觉在分配实际的内存的时候会餐口capacity的大小,如果事先指定容量就会在原来的基础上分配而不是重新分配一次,这样不会出现内存碎片,对于那种大型的对象,效率会提高不少,...
阅读全文
摘要:#include #include #include #include boost::atomic_int producer_count(0);boost::atomic_int consumer_count(0);boost::lockfree::stack stack(128);//多生产者多消...
阅读全文
摘要:#include #include #include #include boost::atomic_int producer_count(0);boost::atomic_int consumer_count(0);boost::lockfree::queue queue(128);//无锁的多生产...
阅读全文
摘要:只作了解,要想深入可以http://www.cnblogs.com/haippy/p/3252056.html看个最简单的例子#include #include #include #include #include using namespace std;boost::atomic_int a ;/...
阅读全文
摘要:#include // std::cout#include // std::thread#include // std::mutex, std::unique_lock#include // st...
阅读全文
摘要:#include // std::cout#include // std::thread, std::this_thread::yield#include // std::mutex, std::uniq...
阅读全文
摘要:#include // std::cout#include // std::thread#include // std::mutex, std::unique_lock#include // st...
阅读全文
摘要:想我什么时候c++,c用的时候可以顺手拈来,不在为c++,c那些基础的东西困扰,像经理说的样,看程序就像看小说一样,到那时可以说已经跳过了初级程序员的过程了。要多加练习,多想想,有没有更好的方法,更有效率的方法。
阅读全文
摘要:上次看到这个有点晕了,其实这个vector保存的是std::vector#include #include using namespace std;int main(){ std::vector > num; std::vector a(10, 5); num.push_back(...
阅读全文
摘要:#include using namespace std;int main(){ //1.const_cast //const int a = 10; //int* ptr = const_cast(&a);//将const属性去除 //*ptr = 100; //2....
阅读全文
摘要:本来看看return到底做了什么结果看了这个复制构造函数,复制构造函数调用的场合如下:• 根据另一个同类型的对象显式或隐式初始化一个对象。• 复制一个对象,将它作为实参传给一个函数。//传递实参的副本时会调用• 从函数返回时复制一个对象。//return返回一个副本时会调用• 初始化顺序容器中的元素...
阅读全文
摘要:我们知道在C++的创建对象是一个费时,费空间的一个操作。有些固然是必不可少,但还有一些对象却在我们不知道的情况下被创建了。通常以下三种情况会产生临时对象: 1,以值的方式给函数传参; 2,类型转换; 3,函数需要返回一个对象时;现在我们依次看这三种情况:一,以值的方式给函数传参。 我们知道给函数传参...
阅读全文
摘要:string str("12345");string str = "12345";在写代码时忽然想到这个两个有啥区别呢,其实这个还是c++基础薄弱的原因于是我又翻开了primerc++支持两种初始化方式:复制初始化和直接初始化int ival(1024);//直接初始化int ival = 1024...
阅读全文
摘要://http://zh.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr#include #include void fun(int* p){}int main(){ { std::shared_ptr ptr = std::...
阅读全文
摘要:#include typedef int (__stdcall* FUN)(int);//定义函数指针,参数为Int,返回为int,调用约定__stdcallint __stdcall fun1(int x){ std::cout << x << std::endl; return x;...
阅读全文
摘要:(int)()这个是c语言的强制转换,众所知周int(),这种理解靠谱点Class A{A(int i){}}调用int类型的构造函数然后转换的其实都可以转换。
阅读全文
摘要:我看我们项目创建线程从来不join,detach#include #include #include #include void fun(){ while (true) { std::cout << "hehhe" << std::endl; }}int main()...
阅读全文
摘要:c++ primer说公有的函数就是接口现在项目中struct I_XX{ virtual void test() = 0;};这个test才被称作接口,我就不知道什么到底是接口,貌似这种说靠谱点接口有不同层次的定义, 比如C++通常把类的公用成员函数函数说成接口; 比如,我们通常把Win API...
阅读全文

浙公网安备 33010602011771号