posted @ 2013-02-23 21:54
02 2013 档案
摘要:对于线程任务比较轻量,线程请求又比较多的情况,频繁的创建和销毁线程是非常消耗资源且低效的。这时候,就轮到线程池技术大显身手了。线程池技术可以提高资源的利用率,即使面对突发性的大量请求,也不会产生大量线程,造成服务器崩溃。一般一个简单线程池至少包含下列组成部分:线程池管理器(ThreadPoolManager):用于创建并管理线程池。工作线程(WorkThread): 线程池中线程。任务接口(Task):每个任务必须实现的接口,以供工作线程调度任务的执行。任务队列:用于存放没有处理的任务。提供一种缓冲机制。线程相关接口:下面是一个线程池的示例,来自http://hi.baidu.com/boah
阅读全文
摘要:1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 int main() { 6 string strA = "Copy on write"; 7 string strB = strA; 8 string strC = strA; 9 printf("strA: %p\r\n", strA.c_str());10 printf("strB: %p\r\n", strB.c_str());11 printf("strC
阅读全文
posted @ 2013-02-18 22:17
摘要:当程序崩溃的时候怎么办 PART-1当程序崩溃的时候怎么办 PART-2
阅读全文
posted @ 2013-02-18 21:07
摘要:#define foreach(container,it) for(typeof((container).begin()) it = (container).begin();it!=(container).end();++it)demo:#include <iostream>#include <vector>#include <set>#include <map>#include <string>using namespace std; #define foreach(container,it) for(typeof((contain
阅读全文
posted @ 2013-02-18 20:53
摘要:In software, astack overflowoccurs when too muchmemoryis used on thecall stack. The call stack contains a limited amount of memory, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-thread
阅读全文
posted @ 2013-02-18 20:11
摘要:// malloc 的写法char* buffer = (char*)malloc(1024);if(buffer) { printf("malloc success!\r\n"); }free(buffer);// new的写法try { char* buffer = new char[1024];}catch(...) { printf("operator new error!\r\n");}delete []buffer;对于malloc方式申请的内存,通过是否是零指针区别;对于new方式申请的内存,通过C++异常机制处理。小细节,大问题。
阅读全文
posted @ 2013-02-17 22:11
摘要:如今大部分编译器的随机数算法还是线性同余算法,简称LCG。线性同余算法(LCG):http://en.wikipedia.org/wiki/Linear_congruential_generatorALinear Congruential Generator(LCG) represents one of the oldest and best-knownpseudorandomnumbergeneratoralgorithms.The generator is defined by therecurrencerelation:whereis thesequenceof pseudorandom
阅读全文
posted @ 2013-02-13 22:18
浙公网安备 33010602011771号