This project is still under development.
The full documentation can be found here.
An object_pool
is a container which provides shared access to a collection of instances of one object of type T
. One only needs to include the header object_pool.hpp
to be able to use it. Even more, the interface is designed á la STL for ease of use! Take the following example for demonstration purposes:
#include "object_pool.hpp"
using namespace carlosb;
struct expensive_object
{
expensive_object()
{
/* very expensive construction */
}
};
int main()
{
object_pool<expensive_object> pool(10); // pool of 10 objects!
if (auto obj = pool.acquire())
doSomething(*obj);
else
doSomethingElse();
return 0;
}
// when the object goes out of scope, it will get returned to the pool
// when the pool goes out of scope, it will delete all objects
To illustrate a typical call to an access function we provide the following example:
#include <iostream>
#include "object_pool.hpp"
using namespace std;
using namespace carlosb;
int main()
{
object_pool<int> pool; // empty pool
pool.push(10); // push 10 into pool
if (auto obj = pool.acquire())
cout << "We acquired: " << *obj << "\n";
else
cout << "We didn't acquire an object" << "\n";
return 0;
}
Output:
We acquired: 10
The software is licensed under the Boost Software License 1.0.