System.Buffers Provides a resource pool that enables reusing instances of type . Renting and returning buffers with an can increase performance in situations where arrays are created and destroyed frequently, resulting in significant memory pressure on the garbage collector. This class is thread-safe. All members may be used by multiple threads concurrently. The lazily-initialized shared pool instance. Retrieves a shared instance. The shared pool provides a default implementation of that's intended for general applicability. It maintains arrays of multiple sizes, and may hand back a larger array than was actually requested, but will never hand back a smaller array than was requested. Renting a buffer from it with will result in an existing buffer being taken from the pool if an appropriate buffer is available or in a new buffer being allocated if one is not available. Ensures that has been initialized to a pool and returns it. Creates a new instance using default configuration options. A new instance. Creates a new instance using custom configuration options. The maximum length of array instances that may be stored in the pool. The maximum number of array instances that may be stored in each bucket in the pool. The pool groups arrays of similar lengths into buckets for faster access. A new instance with the specified configuration options. The created pool will group arrays into buckets, with no more than in each bucket and with those arrays not exceeding in length. Retrieves a buffer that is at least the requested length. The minimum length of the array needed. An that is at least in length. This buffer is loaned to the caller and should be returned to the same pool via so that it may be reused in subsequent usage of . It is not a fatal error to not return a rented buffer, but failure to do so may lead to decreased application performance, as the pool may need to create a new buffer to replace the one lost. Returns to the pool an array that was previously obtained via on the same instance. The buffer previously obtained from to return to the pool. If true and if the pool will store the buffer to enable subsequent reuse, will clear of its contents so that a subsequent consumer via will not see the previous consumer's content. If false or if the pool will release the buffer, the array's contents are left unchanged. Once a buffer has been returned to the pool, the caller gives up all ownership of the buffer and must not use it. The reference returned from a given call to must only be returned via once. The default may hold onto the returned buffer in order to rent it again, or it may release the returned buffer if it's determined that the pool already has enough buffers stored. The reason for a BufferAllocated event. The pool is allocating a buffer to be pooled in a bucket. The requested buffer size was too large to be pooled. The pool has already allocated for pooling as many buffers of a particular size as it's allowed. Event for when a buffer is rented. This is invoked once for every successful call to Rent, regardless of whether a buffer is allocated or a buffer is taken from the pool. In a perfect situation where all rented buffers are returned, we expect to see the number of BufferRented events exactly match the number of BuferReturned events, with the number of BufferAllocated events being less than or equal to those numbers (ideally significantly less than). Event for when a buffer is allocated by the pool. In an ideal situation, the number of BufferAllocated events is significantly smaller than the number of BufferRented and BufferReturned events. Event raised when a buffer is returned to the pool. This event is raised regardless of whether the returned buffer is stored or dropped. In an ideal situation, the number of BufferReturned events exactly matches the number of BufferRented events. The default maximum length of each array in the pool (2^20). The default maximum number of arrays per bucket that are available for rent. Lazily-allocated empty array used when arrays of length 0 are requested. Gets an ID for the pool to use with events. Provides a thread-safe bucket containing buffers that can be Rent'd and Return'd. Creates the pool with numberOfBuffers arrays where each buffer is of bufferLength length. Gets an ID for the bucket to use with events. Takes an array from the bucket. If the bucket is empty, returns null. Attempts to return the buffer to the bucket. If successful, the buffer will be stored in the bucket and true will be returned; otherwise, the buffer won't be stored, and false will be returned. The buffer is not associated with this pool and may not be returned to it.