MemoryPool Class

This class allocates and pools unmanaged memory. Designed to be internally thread safe.

Definition

Namespace: SnapDB.IO.Unmanaged
Assembly: SnapDB (in SnapDB.dll) Version: 1.0.102.0 -- Release Build+29075351d0e5aa4dea46a5c520805222f672dc2e
public class MemoryPool : IDisposable
Inheritance
Object    MemoryPool
Implements
IDisposable

Remarks

Be careful how this class is referenced. Deadlocks can occur when registering to event RequestCollection and when calling AllocatePage(Int32, IntPtr).

Constructors

MemoryPool Creates a new MemoryPool.

Properties

AllocatedBytes Returns the number of bytes currently allocated by the buffer pool to other objects.
CurrentAllocatedSize Returns the number of bytes allocated by all buffer pools. This does not include any pages that have been allocated but are not in use.
CurrentCapacity Gets the number of bytes that have been allocated to this buffer pool by the OS.
IsDisposed Gets if this pool has been disposed.
MaximumPoolSize The maximum amount of RAM that this memory pool is configured to support. Attempting to allocate more than this will cause an out of memory exception.
TargetUtilizationLevel Gets the current TargetUtilizationLevels.

Methods

AllocatePage Requests a page from the buffered pool. If there is not a free one available, method will block and request a collection of unused pages by raising RequestCollection event.
Dispose Releases all the resources used by the MemoryPool object.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
ReleasePage Releases the page back to the buffer pool for reallocation.
ReleasePages Releases all of the supplied pages.
SetMaximumBufferSize Changes the allowable maximum buffer size.
SetTargetUtilizationLevel Changes the utilization level.
ToStringReturns a string that represents the current object.
(Inherited from Object)

Events

RequestCollection Requests that classes using this MemoryPool release any unused buffers. Failing to do so may result in an OutOfMemoryException to occur.

Fields

MaximumTestedSupportedMemoryCeiling Represents the ceiling for the amount of memory the buffer pool can use (124GB).
MinimumTestedSupportedMemoryFloor Represents the minimum amount of memory that the buffer pool needs to work properly (10MB).
PageMask Provides a mask that the user can apply that can be used to get the offset position of a page.
PageShiftBits Gets the number of bits that must be shifted to calculate an index of a position. This is not the same as a page index that is returned by the allocate functions.
PageSize Each page will be exactly this size (based on RAM).

See Also