...
Info |
---|
The documentation uses a byte array of 4096 as poolable object as example. If _poolManager is used in the code below, it represents an instance of PoolManager<Buffer4096Poolable> |
Introduction to the pool manager
The pool manager internally uses a stack to manage the available objects in the pool. It's important to understand how a pool works. The flow diagram below shows how the pool manager deals with objects:
Retrieving objects from the pool
Returning objects to the pool
Objects should be automatically returned to the pool when the objects are disposed. This means the objects are not really disposed but the state is being reset and the object is being returned to the pool. To automatically take care of this, it's best to use the PoolManager<TPoolable> as shown below:
Code Block |
---|
using (var poolableBuffer = _poolManager.GetObject())
{
var buffer = poolableBuffer.Data;
// work with the buffer here
}
// outside the scope, the object is automatically disposed and returned to the pool |
Customizing a pool manager
...