libcruft-util/pool.hpp

54 lines
1.4 KiB
C++
Raw Normal View History

/*
* This file is part of libgim.
*
* libgim is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
2012-08-22 16:12:26 +10:00
* Copyright 2011-2012 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_POOL_HPP
#define __UTIL_POOL_HPP
#include "nocopy.hpp"
namespace util {
2012-08-22 16:12:26 +10:00
template <typename T>
class pool : public nocopy {
protected:
union node {
char _data[sizeof (T)];
node *_chain;
};
node *m_head;
node *m_next;
unsigned int m_capacity;
public:
2012-08-22 16:12:26 +10:00
pool (unsigned int _capacity);
~pool ();
2012-08-22 16:12:26 +10:00
unsigned int capacity (void) const;
template <typename ...Args>
2012-08-22 16:12:26 +10:00
T* acquire (Args&... args);
2012-08-22 16:12:26 +10:00
void release (T *data);
};
}
2012-08-22 16:12:26 +10:00
#include "pool.ipp"
#endif // __UTIL_POOL_HPP