Show / Hide Table of Contents

Class ElementPool<TElement>

A pool of elements Element pools can be used to reduce the amount of garbage collection needed by re-using existing elements instead of creating new ones.

Inheritance
object
ElementPool<TElement>
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: SlipeServer.Server.PacketHandling
Assembly: SlipeServer.Server.dll
Syntax
public class ElementPool<TElement> where TElement : Element
Type Parameters
Name Description
TElement

The type of elements to be stored within this pool

Constructors

| Edit this page View Source

ElementPool(int, bool)

Creates an element pool

Declaration
public ElementPool(int maxElementCount = 64, bool returnsWhenDestroyed = true)
Parameters
Type Name Description
int maxElementCount

The maximum amount of elements to store within this element pool that are not in use

bool returnsWhenDestroyed

Whether or not an element should be returned to the element pool (marked as not in use) when it is destroyed

Methods

| Edit this page View Source

GetOrCreateElement(Func<TElement>, Action<TElement>?)

Gets an element from the pool, or a new element if there are none available within the pool.

Declaration
public TElement GetOrCreateElement(Func<TElement> createCall, Action<TElement>? cleanupCall = null)
Parameters
Type Name Description
Func<TElement> createCall

Action that will be called to create a new element for the pool

Action<TElement> cleanupCall

Action that will be called to clean up an element in the pool prior to releases it to be reused

Returns
Type Description
TElement
| Edit this page View Source

ReturnElement(TElement)

Returns an element to the element pool, marking it as ready to be re-used Only returns the element if there is enough space in the pool based on the maximum element count.

Declaration
public void ReturnElement(TElement element)
Parameters
Type Name Description
TElement element
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX