随笔分类 -  C++

摘要:- **Why can I access private variables in the copy constructor?**The access modifiers work on **class level**, and not on object level.That is, two ob... 阅读全文
posted @ 2014-05-10 10:44 Apprentice_ 阅读(181) 评论(0) 推荐(0)
摘要:本篇文章摘抄于——http://stackoverflow.com/questions/470683/memory-allocation-deallocation-bottleneck,主要讲了C/C++堆内存分配和释放导致性能问题的原因,并给出了基本的解决方案。C/C++堆内存分配和释放,即通过malloc/free或new/delete操作内存,主要会引起两个问题:一是内存碎片;二是堆内存操作需多线程同步,加锁(OS级别)。============================================================================Q:How mu 阅读全文
posted @ 2013-09-03 23:02 Apprentice_ 阅读(401) 评论(0) 推荐(0)
摘要:原贴请见:http://jinnsky2006.spaces.live.com/Blog/cns!27D75A3853CE1DBA!915.entry转载自:http://blog.csdn.net/fxpbupt/article/details/5600937----------------------------------------------------------------------------------------------------当定义一个命名空间时,可以省略命名空间的名称:1 namespce {2 char c;3 int i;4 dou... 阅读全文
posted @ 2013-08-22 22:00 Apprentice_ 阅读(583) 评论(0) 推荐(0)
摘要:class ConnectionHandler{ bool is_conn_close_; Connection* conn_;public: explicit ConnectionHandler(Connection* conn): conn_(conn), is_conn_close_(false){} void Close() { try{ conn_ -> close(); } catch(...){ //... ... 阅读全文
posted @ 2013-05-18 11:40 Apprentice_ 阅读(585) 评论(1) 推荐(1)
摘要:转自:http://stackoverflow.com/questions/395123/raii-and-smart-pointers-in-cA simple (and perhaps overused) example of RAII is a File class. Without RAII, the code might look something like this:File file("/path/to/file");// Do stuff with filefile.close();In other words, we must make sure tha 阅读全文
posted @ 2013-04-27 16:57 Apprentice_ 阅读(277) 评论(0) 推荐(0)