Object Pool
The object pool creational design pattern is used to prepare and keep multiple instances according to the demand expectation.
Advantage
Object pool pattern is useful in cases where object initialization is more expensive than object maintenance. It has positive effects on performance due to objects being initialized beforehand.
Disadvantage
If there are spikes in demand as opposed to a steady demand, the maintenance overhead might outweigh the benefits.
Example
For example, I have solider which requires training before I can initialize it.
I can create an army using a channel. Treat this as a thread-safe queue.
Then I can use the army in my main function.
Last updated