资源简介
线程池 c++
代码片段和文件信息
#include “stdafx.h“
#include “mem_pool.h“
//#include “../auto_lock.h“
//--------------------------------------------MemBlock----------------------------------------------------
#define LOG_TAG “mem pool“
FixedMemBlock::FixedMemBlock(UINT unitSize USHORT unitCount) :
m_blockTotalSize(unitSize * unitCount)
m_freeUnitCount(unitCount - 1)
m_firstFreeIndex(1)
m_pNextBlock(NULL)
m_unitSize(unitSize)
{
char *p = m_firstByte;
//the min index is 1 max index is (unitCount - 1)
//0th unit points to 1th unit 1th points to 2th...(unitCount-2)th points to (unitCount-1)
for (int i = 1; i <= unitCount - 1; ++i)
{
(*(USHORT *)p) = i;
p += unitSize;
}
}
FixedMemBlock::~FixedMemBlock()
{}
void *FixedMemBlock::getFirstFreeUnit()
{
void *pRet = NULL;
if(m_freeUnitCount > 0)
{
pRet = m_firstByte + ((UINT)m_firstFreeIndex) * m_unitSize;
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “alloc unit %i %i from %i“ m_firstFreeIndex pRet this);
#endif
m_firstFreeIndex = *(USHORT *)pRet;
m_freeUnitCount--;
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “next unit %i“ m_firstFreeIndex);
PRINT_I(LOG_TAG “current unit count %i“ m_freeUnitCount);
PRINT_I(LOG_TAG “--------------------------“);
#endif
}
return pRet;
}
bool FixedMemBlock::containsUnit(void *addr)
{
ULONG l = (ULONG)addr;
return (l >= (ULONG)(m_firstByte) && l < (ULONG)(m_firstByte + m_blockTotalSize));
}
void FixedMemBlock::releaseUnit(void *p)
{
//when invoke this method should guarantee that p definitely belongs to this block
//so it‘s private not allow user to invoke it
//write the pre-free index to the head of the unit
*(USHORT *)p = m_firstFreeIndex;
m_firstFreeIndex = (USHORT)(((ULONG)p - (ULONG)(m_firstByte)) / m_unitSize);
m_freeUnitCount++;
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “release unit %i from %i“ m_firstFreeIndex this);
PRINT_I(LOG_TAG “current unit count %i“ m_freeUnitCount);
#endif
}
void * FixedMemBlock::operator new(size_t UINT unitSize UINT unitCount)
{
void *ret = ::operator new(sizeof(FixedMemBlock) + unitSize * unitCount);
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “alloc new block %i“ ret);
#endif
return ret;
}
void FixedMemBlock::operator delete(void *p UINT unitSize UINT unitCount)
{
if (p)::operator delete(p);
}
void FixedMemBlock::operator delete(void *p size_t)
{
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “release block %i“ p);
#endif
if (p)::operator delete(p);
}
//--------------------------------------------MemPool----------------------------------------------------
FixedMemPool::FixedMemPool():
m_pBlockHead(NULL)
m_blockCount(0)
m_autoReleaseFreeBlock(false)
m_maxReserveBlocksCount(0)
m_totalAllocSize(0)
m_isInited(false)
m_unitSize(0)
m_unitCountPerBlock(0)
{
}
FixedMemPool::FixedMemPool(UINT unitSize USHORT unitCountPerBlock) :
m_pBlockHead(NULL)
m_blockCount(0)
m_autoReleaseFreeBl
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-08-03 15:31 threadPool\
文件 3083264 2015-08-03 17:25 threadPool.ncb
文件 896 2015-07-23 22:02 threadPool.sln
文件 31232 2015-08-03 17:24 threadPool.suo
目录 0 2015-08-03 15:31 threadPool\Debug\
文件 6706 2015-08-03 15:31 threadPool\Debug\BuildLog.htm
文件 20691 2015-07-24 00:57 threadPool\Debug\mem_pool.obj
文件 65 2015-08-03 15:31 threadPool\Debug\mt.dep
文件 11917 2015-07-23 22:12 threadPool\Debug\stdafx.obj
文件 68561 2015-07-28 22:17 threadPool\Debug\thread.obj
文件 663 2015-07-23 22:12 threadPool\Debug\threadPool.exe.em
文件 728 2015-07-23 22:12 threadPool\Debug\threadPool.exe.em
文件 621 2015-08-03 15:31 threadPool\Debug\threadPool.exe.intermediate.manifest
文件 60963 2015-08-03 15:31 threadPool\Debug\threadPool.obj
文件 3211264 2015-07-23 22:12 threadPool\Debug\threadPool.pch
文件 353307 2015-08-03 15:29 threadPool\Debug\ThreadPoolExecutor.obj
文件 666624 2015-08-03 15:31 threadPool\Debug\vc90.idb
文件 389120 2015-08-03 15:31 threadPool\Debug\vc90.pdb
文件 6986 2015-07-24 00:57 threadPool\mem_pool.cpp
文件 2413 2015-07-24 00:57 threadPool\mem_pool.h
文件 1201 2015-07-23 22:02 threadPool\ReadMe.txt
文件 215 2015-07-23 22:02 threadPool\stdafx.cpp
文件 233 2015-07-23 22:02 threadPool\stdafx.h
文件 498 2015-07-23 22:02 threadPool\targetver.h
文件 2441 2015-07-24 00:58 threadPool\thread.cpp
文件 1624 2015-07-23 22:04 threadPool\thread.h
文件 785 2015-08-03 15:31 threadPool\threadPool.cpp
文件 4901 2015-07-24 00:55 threadPool\threadPool.vcproj
文件 1413 2015-08-03 17:24 threadPool\threadPool.vcproj.zhang-PC.zhang.user
文件 5553 2015-08-03 15:28 threadPool\ThreadPoolExecutor.cpp
文件 2211 2015-07-24 00:52 threadPool\ThreadPoolExecutor.h
............此处省略0个文件信息
相关资源
- 网络五子棋全功能版
- 清华大学数据结构算法及源代码
- 利用开源库bssQRCodeGenerator.dll创建最最
- 基于C++MFC的聊天程序,C/S模式
- C/C++使用遗传算法解决车辆路径问题
- C++delaunay三角网代码
- 21点游戏MFC程序设计 c++课程设计
- C、C++函数速查手册 (chw版)
- C++综合实验,继承和派生类的设计及
- c++ 串口开发 发送/接受数据demo
- C++ Builder 6程序设计教程.pdf c builder
- c++程序实现c++代码相似度计算
- 成绩查询系统VC++源代码
- 华为C++语言编程规范
- C++项目源代码适合新手练手及参考
- 华西期货上期CTP程序化交易C++高效策
- 多目标跟踪c++代码290025
- OPC UA C++写的服务器和客户端 linux下的
- C++写的即时通讯软件
- Visual C++从入门到精通第三版.pdf28983
- C++Primer plus(第六版)中文版书后编程
- C++ bp神经网络算法
- C++商品销售管理系统(源码)
- VC++实现视频采集
- c/c++源码浏览工具卷2
- VC++ 图像文字提取
- 易学C++ 潘嘉杰 完整版+答案
- C++ Primer 5th edition PDF完美版
- C++ 英文教材+ppt+exercise
- VC++6.0安装包中文版
评论
共有 条评论