Class PooledObjectBuffer<T>
- Namespace
- CodeProject.ObjectPool.Core
- Assembly
- CodeProject.ObjectPool.dll
A buffer into which pooled objects are stored. This buffer mostly behaves like a queue, even if that behavior is not strictly respected in order to maximize performance.
public sealed class PooledObjectBuffer<T> : IEnumerable<T>, IEnumerable where T : PooledObject
Type Parameters
TThe type of the object that which will be managed by the pool. The pooled object have to be a sub-class of PooledObject.
- Inheritance
-
PooledObjectBuffer<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Properties
Capacity
The maximum capacity of this buffer.
public int Capacity { get; }
Property Value
Count
The number of objects stored in this buffer.
public int Count { get; }
Property Value
Methods
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the collection.
Resize(int)
Resizes the buffer so that it fits to given capacity. If new capacity is smaller than current capacity, then exceeding items are returned.
public IList<T?> Resize(int newCapacity)
Parameters
newCapacityintThe new capacity of this buffer.
Returns
- IList<T>
All exceeding items.
TryDequeue(out T?)
Tries to dequeue an object from the buffer.
public bool TryDequeue(out T? pooledObject)
Parameters
pooledObjectTOutput pooled object.
Returns
- bool
True if
pooledObjecthas a value, false otherwise.
TryEnqueue(T)
Tries to enqueue given object into the buffer.
public bool TryEnqueue(T pooledObject)
Parameters
pooledObjectTInput pooled object.
Returns
- bool
True if there was enough space to enqueue given object, false otherwise.
TryRemove(T)
Tries to remove given object from the buffer.
public bool TryRemove(T pooledObject)
Parameters
pooledObjectTPooled object to be removed.
Returns
- bool
True if
pooledObjecthas been removed, false otherwise.