博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
内存池和tcmalloc的性能比较
阅读量:6955 次
发布时间:2019-06-27

本文共 1310 字,大约阅读时间需要 4 分钟。

这次使用的内存池是原公司的,利用hash_map做的,大概的接口是这样:

template 
class ObjectPool{ public: typedef hash_map
BlockMap; virtual int pop(CObject *&ob); virtual int push(const CObject *ob); private: BlockMap _block_map;};

写测试代码比较了一下内存池和tcmalloc的差距!结果挺让人吃惊!

#define MAX_SIZE 50000struct MsgToPut{	 UINT _wr_ptr;	 UINT _rd_ptr;	 UINT _length;	 CHAR _base[1024];	 void reset()	 {		 this->_rd_ptr = this->_wr_ptr = 0;		 this->_length = 1024;	 }};ObjectPool
MsgPool;void* newthread(void* argv){ long long int start = get_os_system_time(); for(int i=0;i
reset(); } start = get_os_system_time(); printf("newthread tc malloc :%d\n",start - end); return (void*)0;}int main(){ pthread_t pid; pthread_create(&pid,NULL,newthread,NULL); pthread_create(&pid,NULL,newthread,NULL); pthread_create(&pid,NULL,newthread,NULL); long long int start = get_os_system_time(); for(int i=0;i
reset(); } start = get_os_system_time(); printf("main tc malloc :%d\n",start - end); return 0;}

普遍打印数据为:

newthread ObjectPool:189

newthread ObjectPool:202
newthread tc malloc :24
newthread tc malloc :20
main ObjectPool:235
newthread ObjectPool:235
main tc malloc :21
newthread tc malloc :22

转载于:https://www.cnblogs.com/archy_yu/archive/2013/03/25/2980196.html

你可能感兴趣的文章
First Missing Positive && missing number
查看>>
SharePoint服务器端对象模型 之 使用CAML进行数据查询(Part 4)
查看>>
10条设计师应该知道的字体设置技巧
查看>>
Mac Brew Uninstall MySql
查看>>
LeetCode刷题笔记-回溯法-分割回文串
查看>>
Serv-U和win2003防火墙的设置
查看>>
【网摘】ActiveX组件及其注册
查看>>
Bootstrap网格系统(Grid System)
查看>>
linux内核参数优化
查看>>
Utils工具方法集插件详解
查看>>
Windows Server定时执行bat
查看>>
Linux RTC Test Example rtctest.c hacking
查看>>
Linux C enum
查看>>
递增三元数组——第九届蓝桥杯C语言B组(省赛)第六题
查看>>
字符,字节和编码, ASCII码, DBCS码,SBCS码 与Unicode码
查看>>
物件捆绑 背包问题 动态规划 求解
查看>>
finish
查看>>
查看系统信息msinfo32工具的使用
查看>>
iso系统镜像刻录到光盘和U盘
查看>>
tcp四次挥手
查看>>