mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
Pool is a place to store shared_ptrs to generated objects (T) that are too expensive to create and destroy between individual uses, such as temporary files. Objects in a Pool have no distinct identity (contrast with Cache or NamedPtr). Users of the Pool invoke the Pool function call overload and "check out" a shared_ptr<T> for a T object from the Pool. When the last referencing shared_otr<T> is destroyed, the T object is "checked in" to the Pool. Each call of the Pool function overload checks out a shared_ptr<T> to a T object that is not currently referenced by any other public shared_ptr<T>. If there are no existing T objects in the Pool, a new T is constructed by calling the generator function. The clear() method destroys all checked in T objects owned by the Pool at the time the method is called. T objects that are checked out are not affected by clear(), and they will be stored in the Pool when they are checked in. If the checkout function is provided, it is called on a shared_ptr<T> during checkout, before returning to the caller. If the checkin function is provided, it is called on a shared_ptr<T> before returning it to the Pool. The checkin function must not throw exceptions. The Pool may be destroyed while T objects are checked out of the Pool. In that case, when the T objects are checked in, the T object is immediately destroyed without calling the checkin function. Signed-off-by: Zygo Blaxell <bees@furryterror.org>