07 2012 档案
摘要:std::move是一个用于提示优化的函数,过去的c++98中,由于无法将作为右值的临时变量从左值当中区别出来,所以程序运行时有大量临时变量白白的创建后又立刻销毁,其中又尤其是返回字符串std::string的函数存在最大的浪费。比如:1 std::string fileContent = “oldContent”;2 s = readFileContent(fileName);因为并不是所有情况下,C++编译器都能进行返回值优化,所以,向上面的例子中,往往会创建多个字符串。readFileContent如果没有内部状态,那么,它的返回值多半是std::string(const std::st
阅读全文
摘要:今天看到boost::unordered_map, 它与 stl::map的区别就是,stl::map是按照operator<比较判断元素是否相同,以及比较元素的大小,然后选择合适的位置插入到树中。所以,如果对map进行遍历(中序遍历)的话,输出的结果是有序的。顺序就是按照operator< 定义的大小排序。而boost::unordered_map是计算元素的Hash值,根据Hash值判断元素是否相同。所以,对unordered_map进行遍历,结果是无序的。用法的区别就是,stl::map 的key需要定义operator< 。 而boost::unordered_map
阅读全文
摘要:/**用来测试STLhash_map*简单例子2008.5.5*/#include<cstdlib>#include<iostream>#include<string>#include<hash_map.h>/*因为hash_map暂不为CPP标准所以没办法写为<hash_map>*//*-------------------------------------------*/usingstd::cout;usingstd::endl;usingstd::string;/*-------------------------------
阅读全文
摘要:<p>#include"stdafx.h"#include<iostream>#include<hash_map>#include<vector></p><p>usingstd::vector;usingstdext::hash_map;</p><p>classhash_wchar_t{public://以下两个变量我也不是很明白究竟是干嘛的staticconstsize_tbucket_size=4;//猜测这个变量是初始化hash_map的大小staticconstsize_
阅读全文
摘要:Epoll基本介绍在linux的网络编程中,很长的时间都在使用select来做事件触发。在linux新的内核中,有了一种替换它的机制,就是epoll。相比于select,epoll最大的好处在于它不会随着监听fd数目的增长而降低效率。因为在内核中的select实现中,它是采用轮询来处理的,轮询的fd数目越多,自然耗时越多。并且,在linux/posix_types.h头文件有这样的声明:#define__FD_SETSIZE1024表示select最多同时监听1024个fd,当然,可以通过修改头文件再重编译内核来扩大这个数目,但这似乎并不治本。epoll的接口非常简单,一共就三个函数:1.in
阅读全文
摘要:Editor's note: This article refers to the Java Memory Model before it was revised for Java 5.0; statements about memory ordering may no longer be correct. However, the double-checked locking idiom is still broken under the new memory model. For more information on the memory model in Java 5.0, s
阅读全文

浙公网安备 33010602011771号