Table of Contents

Struct ObjectOwner<T>

Namespace
CryptoHives.Foundation.Memory.Pools
Assembly
CryptoHives.Foundation.Memory.dll

Owner of object shared from ObjectPool<T> who is responsible for disposing the underlying object appropriately.

public readonly struct ObjectOwner<T> : IDisposable, IEquatable<ObjectOwner<T>> where T : class

Type Parameters

T
Implements
Inherited Members

Remarks

Use only in a limited scope such as in a using statement to ensure that the ObjectOwner struct is not copied and the object is returned to the pool, e.g.

using var owner = new ObjectOwner<MyType>(myPool);
MyType obj = owner.Object;

Note: do not cast to IDisposable to avoid a boxing allocation.

Constructors

ObjectOwner(ObjectPool<T>)

Initializes a new instance of the ObjectOwner<T> struct.

public ObjectOwner(ObjectPool<T> objectPool)

Parameters

objectPool ObjectPool<T>

Properties

PooledObject

The pooled Object obtained from the pool.

public T PooledObject { get; }

Property Value

T

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Equals(ObjectOwner<T>)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(ObjectOwner<T> other)

Parameters

other ObjectOwner<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Operators

operator ==(ObjectOwner<T>, ObjectOwner<T>)

Determines whether two ObjectOwner instances are equal.

public static bool operator ==(ObjectOwner<T> left, ObjectOwner<T> right)

Parameters

left ObjectOwner<T>
right ObjectOwner<T>

Returns

bool

operator !=(ObjectOwner<T>, ObjectOwner<T>)

Determines whether two ObjectOwner instances are not equal.

public static bool operator !=(ObjectOwner<T> left, ObjectOwner<T> right)

Parameters

left ObjectOwner<T>
right ObjectOwner<T>

Returns

bool