C++中一个高效的内存池实现 (二)

2014-11-24 12:06:15 · 作者: · 浏览: 1
ol;
};

//CMemoryPool* CTest::s_pool = NULL;
CMTMemoryPool, CCriticalSection>* CTest::s_pool = NULL;

void testFun()
{
int i;
const int nLoop = 10;
const int nCount = 10000;

for(int j = 0; j {
typedef CTest* LPTest;
LPTest arData[nCount];
for(i=0;i {
arData[i] = new CTest;
}

for(i=0;i {
delete arData[i];
}
}
}

int main(int argc, char* argv[])
{
{
unsigned int dwStartTickCount = GetTickCount();

CTest::NewPool();

testFun();

CTest::DeletePool();

cout << "total cost" << GetTickCount() - dwStartTickCount << endl;
}


system("pause");

return 0;
}
在我机器上测试结果比系统默认的CRT实现高效N倍。

摘自 厚积薄发