I wanna design a Concurrent object pool in C++, possible prototype as:
template<std::size_t OBJ_SIZE>
class Pool {
public:
template<typename T>
void new(std::shared_ptr<T> & product);
// more details...
};
- Once object(product) is returned, its lifetime is fully controlled by the smart pointer(s) containing the object.
- Pool may be used by multiple threads.
How do we automatically reclaim the object/memory after user is done with it?
My idea is to have a delete() method in pool, which is called in product's destructor.
Is there a better design? e.g. a way where product classes are less coupled with Pool (note it's a generic pool). Any idea is welcomed.