- 博客(61)
- 资源 (3)
- 收藏
- 关注
转载 stl map vector的删除
http://blog.chinaunix.net/uid-630435-id-88932.html std::list List; std::list::iterator itList; for( itList = List.begin(); itList != List.end(); ) { if( Wi
2015-04-03 11:50:11
428
转载 为什么一般hashtable的桶数会取一个素数
http://blog.sina.com.cn/s/blog_8e9c63c70101g3ep.html我个人认为更普遍意义的理解,如果不取素数的话是会有一定危险的,危险出现在当假设所选非素数m=x*y,如果需要hash的key正好跟这个约数x存在关系就惨了,最坏情况假设都为x的倍数,那么可以想象hash的结果为:1~y,而不是1~m。但是如果选桶的大小为素数是不会有这个问
2015-02-06 10:52:07
1671
原创 用objgraph定位python内存泄漏
http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks/http://mg.pov.lt/objgraph/http://mg.pov.lt/blog/python-object-graphs.html注:要生成对象引用图片,不一定要安装xdot,也可以用graphviz。yum -y instal
2015-02-02 09:27:15
2419
转载 C++ 拷贝构造函数 赋值构造函数
http://blog.chinaunix.net/uid-25808509-id-354211.html拷贝构造函数和赋值构造函数的异同由于并非所有的对象都会使用拷贝构造函数和赋值函数,程序员可能对这两个函数有些轻视。请先记住以下的警告,在阅读正文时就会多心:如果不主动编写拷贝构造函数和赋值函数,编译器将以“位拷贝”的方式自动生成缺省的函数。倘若类中含有指针变量,那么这两个缺
2015-01-09 17:27:23
362
转载 LSM-Tree 相关
海量存储系列之八 http://qing.blog.sina.com.cn/1765738567/693f0847330008ii.html
2014-10-22 15:47:51
363
转载 memcached的线程模型
http://blog.youkuaiyun.com/tenfyguo/article/details/5274435
2014-08-31 18:29:26
443
转载 内存泄露定位 - MEMWATCH
4. 容易出现的问题4.1 在memwatch.h之后包含string.h时,编译时提示strdup()出错! 解决办法:可以将string.h放置在memwatch.h之前;也可以修改memwatch.h,使其包含string.h.
2014-08-18 10:24:36
716
转载 ev.c
# 1 "ev.c"# 1 ""# 1 ""# 1 "ev.c"# 45 "ev.c"# 1 "config.h" 1# 46 "ev.c" 2# 167 "ev.c"# 1 "/usr/include/stdlib.h" 1 3 4# 25 "/usr/include/stdlib.h" 3 4# 1 "/usr/include/features.h" 1 3 4# 361
2014-07-19 10:10:10
2663
转载 pthread_cond_wait与signal
http://www.domaigne.com/blog/computing/condvars-signal-with-mutex-locked-or-not/Signal with Mutex Locked On some platforms, the OS performs a context switch to the woken thread right after
2014-07-15 07:57:55
510
转载 pthread_once
如果希望多个线程里面某些部分只是执行一次的话,可以使用下面这个接口:pthread_once_t initflag=PTHREAD_ONCE_INIT;int pthread_once(pthread_once_t* initflag,void (*initfn)(void));然后再每个线程里面调用pthread_once.下面是一个例子:#include #include #
2014-07-03 09:45:02
553
转载 可重入函数
假设我们正在执行函数A,而正在这个时候出发了信号处理函数,里面也调用了A.我们必须确保两次调用A的结果都完全正确。如果保证调用完全正确的话,那么这个函数就是可重入函数。很明显可重入函数,对应着就是没有使用全局变量的函数。这里我们需要区分可重入函数和线程安全函数。如果某个函数使用了全局变量,但是在全局变量访问部分保证串行访问的话,那么这个函数就是线程安全函数。可重入函数必然是线程安全函数,而线程
2014-07-03 09:29:01
478
原创 C++内部类
内部类可以访问外部类的private方法。#include #include using namespace std;template class MyList { public: MyList(vector* list): v_(list) { } class Iterator { public:
2014-06-30 14:05:35
805
原创 c++迭代器
有两种实现方式,将迭代器定义在内部(STL方式):http://blog.youkuaiyun.com/lonelywinter340/article/details/3327700将迭代器定义在外部:http://blog.youkuaiyun.com/lcl_data/article/details/9310313殊途同归,都是在调用begin(
2014-06-30 11:37:12
331
原创 lower_bound
#include using namespace std;template size_t find_lower_bound(size_t i, size_t j, T* data, const T& key, bool (*les)(const T&, const T&)) { if (les(key, data[i])) { return i; } while (i
2014-06-29 22:47:49
461
原创 int与int*之间的转换
void test_cast() { int* pa = reinterpret_cast(1); cout pa++; cout cout (pa) }
2014-06-27 18:17:48
2375
原创 将数字序列化到内存
void test_memcpy() { uint32 a = 1235439534; char buf[1024]; memset(buf, 0 , sizeof(buf)); memcpy(buf, &a, sizeof(a)); cout << buf << endl; uint32 b = 0; memcpy(&b, buf, sizeof(b)); cou
2014-06-18 16:19:29
547
原创 测试Std:heap
void test1() { vector va; int a[] = {1,3,5,3,6,4,7,4,9}; for (int i = 0; i < sizeof(a)/sizeof(int); i++) { va.push_back(a[i]); } cout << va.size() << endl; make_heap(va.begin(), va.en
2014-06-18 16:13:50
1053
原创 测试friend成员
#include using namespace std;class A {public: A(string name):name_(name) {}private: friend class B; void Print() { cout << "A" << endl; } string name_;};class B {public: B(A* a): a_(
2014-06-18 16:12:05
442
原创 vector里元素的地址会改变
void PrintVectorAddr(vector& v) { for (size_t i = 0; i cout } cout }void test() { vector v; int a = 1; v.push_back(a); PrintVectorAddr(v); int b = 2; v.push_b
2014-04-11 11:43:44
2902
转载 堆排序
#include void shift(int a[] , int i , int m){int k , t; t = a[i]; k = 2 * i + 1; while (k < m) { if ((k < m - 1) && (a[k] < a[k+1])) k ++; if (t < a[k]) {a[i] = a[k];
2014-02-21 09:32:12
388
原创 map析构类的问题
http://bbs.youkuaiyun.com/topics/390692287?page=1class A { private: int a_; public: A():a_(0) { cout << "create A(" << a_ <<")" << endl;} A(int a):a_(a) { cout << "create A(" << a_<< ")" << en
2014-01-16 10:19:31
2309
原创 C++链接时出现”multiple definition of“错误,或者undefined reference的问题
可能是.h文件里包含了对变量的定义(初始化)导致。应该把变量定义(初始化)放于.cpp文件。
2014-01-13 18:42:11
993
转载 thrift找不到包含的类
http://blog.youkuaiyun.com/shenchen8274/article/details/7285687
2014-01-08 18:42:41
807
原创 epoll初步使用
最近准备学习一下epoll,就写了一个小程序做测试。把中间遇到的问题记录下来,请大家多多指正。代码很简单:一个服务端,接收请求,将接收到的内容再返回给客户端。一个客户端,多线程的发送请求再接收。server.cc#include #include #include #include #include #include #include #include
2013-12-29 09:57:34
597
转载 "undefined reference to" 问题解决方法
http://yiluohuanghun.blog.51cto.com/3407300/1181380
2013-12-23 13:50:33
778
转载 pthread_cond_wait()使用注意点
http://www.cnblogs.com/diyingyun/archive/2011/11/25/2263164.htmlThe mutex passed to pthread_cond_wait protects the condition.The caller passes it locked to the function, which then ato
2013-12-23 10:41:01
951
原创 用epoll实现毫秒sleep
#include #include #include #include int test(){ struct epoll_event; int epfd; struct timeval tv; epfd=epoll_create(1); while(1){ int nfds =
2013-12-20 16:42:06
874
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人