C# 클래스 GSF.IO.Unmanaged.MemoryPool

This class allocates and pools unmanaged memory. Designed to be internally thread safe.
Be careful how this class is referenced. Deadlocks can occur when registering to event RequestCollection and when calling AllocatePage. See comments for these methods for considerations.
상속: IDisposable
파일 보기 프로젝트 열기: GridProtectionAlliance/openHistorian 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
PageMask int
PageShiftBits int
PageSize int

공개 메소드들

메소드 설명
AllocatePage ( int &index, IntPtr &addressPointer ) : void

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.

IMPORTANT NOTICE: Be careful when calling this method as the calling thread will block if no memory is available to have a background collection to occur. There is a possiblity for a deadlock if calling this method from within a lock. The page allocated will not be initialized, so assume that the data is garbage.

Dispose ( ) : void

Releases all the resources used by the MemoryPool object.

MemoryPool ( int pageSize = 64*1024, long maximumBufferSize = -1, TargetUtilizationLevels utilizationLevel = TargetUtilizationLevels.Low ) : System

Creates a new MemoryPool.

ReleasePage ( int pageIndex ) : void

Releases the page back to the buffer pool for reallocation.

The page released will not be initialized. Releasing a page is on the honor system. Rereferencing a released page will most certainly cause unexpected crashing or data corruption or any other unexplained behavior.

ReleasePages ( IEnumerable pageIndexes ) : void

Releases all of the supplied pages

SetMaximumBufferSize ( long value ) : long

Changes the allowable buffer size

SetTargetUtilizationLevel ( TargetUtilizationLevels utilizationLevel ) : void

Changes the utilization level

비공개 메소드들

메소드 설명
CalculateStopShrinkingLimit ( long size ) : long

Calculates at what point a collection cycle will cease prematurely.

CalculateThresholds ( long maximumBufferSize, TargetUtilizationLevels levels ) : void
GetCollectionLevelBasedOnSize ( long size ) : int

Gets the number of collection rounds base on the size.

GetCollectionLevelString ( int iterations ) : string
RemoveDeadEvents ( ) : void

Searches the collection events and removes any events that have been collected by the garbage collector.

RequestMoreFreeBlocks ( ) : void

Determines whether to allocate more memory or to do a collection cycle on the existing pool.

메소드 상세

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.
IMPORTANT NOTICE: Be careful when calling this method as the calling thread will block if no memory is available to have a background collection to occur. There is a possiblity for a deadlock if calling this method from within a lock. The page allocated will not be initialized, so assume that the data is garbage.
public AllocatePage ( int &index, IntPtr &addressPointer ) : void
index int the index id of the page that was allocated
addressPointer System.IntPtr outputs a address that can be used /// to access this memory address. You cannot call release with this parameter. /// Use the returned index to release pages.
리턴 void

Dispose() 공개 메소드

Releases all the resources used by the MemoryPool object.
public Dispose ( ) : void
리턴 void

MemoryPool() 공개 메소드

Creates a new MemoryPool.
public MemoryPool ( int pageSize = 64*1024, long maximumBufferSize = -1, TargetUtilizationLevels utilizationLevel = TargetUtilizationLevels.Low ) : System
pageSize int The desired page size. Must be between 4KB and 256KB
maximumBufferSize long The desired maximum size of the allocation. Note: could be less if there is not enough system memory.
utilizationLevel TargetUtilizationLevels Specifies the desired utilization level of the allocated space.
리턴 System

ReleasePage() 공개 메소드

Releases the page back to the buffer pool for reallocation.
The page released will not be initialized. Releasing a page is on the honor system. Rereferencing a released page will most certainly cause unexpected crashing or data corruption or any other unexplained behavior.
public ReleasePage ( int pageIndex ) : void
pageIndex int A value of zero or less will return silently
리턴 void

ReleasePages() 공개 메소드

Releases all of the supplied pages
public ReleasePages ( IEnumerable pageIndexes ) : void
pageIndexes IEnumerable A collection of pages.
리턴 void

SetMaximumBufferSize() 공개 메소드

Changes the allowable buffer size
public SetMaximumBufferSize ( long value ) : long
value long the number of bytes to set.
리턴 long

SetTargetUtilizationLevel() 공개 메소드

Changes the utilization level
public SetTargetUtilizationLevel ( TargetUtilizationLevels utilizationLevel ) : void
utilizationLevel TargetUtilizationLevels
리턴 void

프로퍼티 상세

PageMask 공개적으로 프로퍼티

Provides a mask that the user can apply that can be used to get the offset position of a page.
public int PageMask
리턴 int

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.
public int PageShiftBits
리턴 int

PageSize 공개적으로 프로퍼티

Each page will be exactly this size (Based on RAM)
public int PageSize
리턴 int