Edit

Share via


StringPool Class

Definition

A configurable pool for String instances. This can be used to minimize allocations when creating multiple String instances from buffers of Char values. The GetOrAdd(ReadOnlySpan<Char>) method provides a best-effort alternative to just creating a new String instance every time, in order to minimize the number of duplicated instances. The StringPool type will internally manage a highly efficient priority queue for the cached String instances, so that when the full capacity is reached, the least frequently used values will be automatically discarded to leave room for new values to cache.

public sealed class StringPool
type StringPool = class
Public NotInheritable Class StringPool
Inheritance
StringPool

Constructors

StringPool()

Initializes a new instance of the StringPool class.

StringPool(Int32)

Initializes a new instance of the StringPool class.

Properties

Shared

Gets the shared StringPool instance.

Size

Gets the total number of String that can be stored in the current instance.

Methods

Add(String)

Stores a String instance in the internal cache.

GetOrAdd(ReadOnlySpan<Byte>, Encoding)

Gets a cached String instance matching the input content (converted to Unicode), or creates a new one.

GetOrAdd(ReadOnlySpan<Char>)

Gets a cached String instance matching the input content, or creates a new one.

GetOrAdd(String)

Gets a cached String instance matching the input content, or stores the input one.

Reset()

Resets the current instance and its associated maps.

TryGet(ReadOnlySpan<Char>, String)

Tries to get a cached String instance matching the input content, if present.

Applies to