#pragma once #include #include #include "threading/sync/lockable.hpp" #include "threading/sync/spinlock.hpp" template > class Recycler : public Lockable { static constexpr size_t default_max_reserved = 100; public: Recycler() = default; Recycler(size_t max_reserved) : max_reserved(max_reserved) {} template T* acquire(Args&&... args) { auto guard = acquire_unique(); return fetch_or_create(std::forward(args)...); } void release(T* item) { auto guard = acquire_unique(); return recycle_or_delete(item); } protected: Allocator alloc; size_t max_reserved {default_max_reserved}; std::queue items; template T* fetch_or_create(Args&&... args) { return new T(std::forward(args)...); // todo refactor :D } void recycle_or_delete(T* item) { delete item; // todo refactor :D } };