Copyright (c) 2013-2018 brinkqiang ([email protected])
Linux | Mac | Windows |
---|---|---|
dmrapidpool
#include <string>
#include <iostream>
#include "dmrapidpool.h"
#include "dmthreadpool.h"
class CPlayer
{
public:
CPlayer(const std::string& name)
: m_strName(name)
{
}
virtual ~CPlayer()
{
}
const std::string& GetName()
{
return m_strName;
}
private:
std::string m_strName;
};
class CMonster
{
public:
CMonster(const std::string& name)
: m_strName(name)
{
}
virtual ~CMonster()
{
}
const std::string& GetName()
{
return m_strName;
}
private:
std::string m_strName;
};
int main(int argc, char* argv[]) {
for (int i = 0; i < 10000; ++i)
{
std::unique_ptr<CPlayer, DMPoolDeleter<CPlayer>> player(DMNew<CPlayer>("name"));
}
for (int i = 0; i < 10000; ++i)
{
std::unique_ptr<CPlayer, DMPoolDeleter<CPlayer>> player;
player.reset(DMNew<CPlayer>("name"));
}
dmthreadpool pool;
for (int i = 0; i < 100; ++i) {
pool.commit([] {
for (int j = 0; j < 100000; ++j)
{
std::unique_ptr<CPlayer, DMPoolDeleter<CPlayer>> player;
player.reset(DMNew<CPlayer>("name"));
}
});
}
pool.wait_idle();
std::cout << DMGetPoolInfo();
return 0;
}