Skip to content

brinkqiang/dmrapidpool

Repository files navigation

dmrapidpool

Copyright (c) 2013-2018 brinkqiang ([email protected])

dmrapidpool GitHub

Build status

Linux Mac Windows
lin-badge mac-badge win-badge

Intro

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;
}

Contacts

Thanks

About

C++ object pool with statistics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages