Table of Contents

Class JCOBridgeObjectPool<T>

Namespace
MASES.JCOBridge.C2JBridge
Assembly
C2JBridge.dll

A lightweight object pool that reduces allocation pressure in high-throughput scenarios. Full pooling behaviour is available only under a JCOBridge High Performance (HPA) license; with a standard license Rent(ref bool) always creates a new instance via the factory delegate.

public sealed class JCOBridgeObjectPool<T>

Type Parameters

T

Type of the pooled objects.

Inheritance
JCOBridgeObjectPool<T>
Inherited Members
Extension Methods

Constructors

JCOBridgeObjectPool(Func<T>, int, int)

Initialises a new pool instance.

public JCOBridgeObjectPool(Func<T> factory, int localMaxSize = 64, int sharedMaxSize = 4096)

Parameters

factory Func<T>

Delegate used to create a new T when no pooled instance is available.

localMaxSize int

Maximum objects retained per thread under a JCOBridge HPA license. Defaults to 64. Ignored with a standard license.

sharedMaxSize int

Maximum objects retained in the shared cross-thread store under a JCOBridge HPA license. Defaults to 4096. Objects returned beyond this limit are silently discarded. Ignored with a standard license.

Properties

IsEnable

Returns true if JCOBridgeObjectPool<T> has pooling enabled (i.e. JCOBridge HPA license), false otherwise

public bool IsEnable { get; }

Property Value

bool

Methods

Rent(ref bool)

Retrieves an instance from the pool, or creates a new one if no pooled instance is available.

public T Rent(ref bool fromPool)

Parameters

fromPool bool

Set to true if the returned instance came from the pool; false if it was freshly created by the factory. Use this flag to determine whether the instance needs to be reset before use. Under a standard license this parameter is always false.

Returns

T

An instance of T.

Return(T)

Returns a previously rented instance to the pool for reuse.

public bool Return(T obj)

Parameters

obj T

The instance to return. Must have been obtained via Rent(ref bool).

Returns

bool

true if the instance in obj was returned to the pool, false otherwise. Under a standard license the return value is always false.

Remarks

The caller is responsible for resetting the instance's state before returning it, to avoid leaking state between consumers. Instances returned beyond the configured capacity are silently discarded. Under a standard license this method is a no-op and the instance is left for the GC.