C# Class BEPUutilities2.ResourceManagement.Allocator

Represents a chunk of abstract memory supporting allocations and deallocations. Never moves any memory.
Uses an extremely simple ring buffer that makes no attempt to skip groups of allocations. Not particularly efficient.
ファイルを表示 Open project: RossNordby/scratchpad Class Usage Examples

Public Methods

Method Description
Allocate ( ulong id, long size, long &outputStart ) : bool

Attempts to allocate a range of memory.

Allocator ( long memoryPoolSize, BufferPool idBufferPool = null, BufferPool allocationBufferPool = null, BufferPool tableBufferPool = null ) : System

Creates a new memory pool.

CanFit ( long size, QuickList ignoredIds = null ) : bool

Checks if a block of memory can fit into the current state of the allocator.

Deallocate ( ulong id ) : bool

Removes the memory associated with the id from the pool.

GetLargestContiguousSize ( long &largestContiguous, long &totalFreeSpace ) : void

Gets the size of the largest contiguous area and the total free space in the allocator. Not very efficient; runs in linear time for the number of allocations.

IncrementalCompact ( ulong &id, long &size, long &oldStart, long &newStart ) : bool

Finds the first allocation with empty space before it and pulls it forward to close the gap. Assumes the ability to perform synchronous reallocation.

Resize ( ulong id, long size, long &oldStart, long &newStart ) : bool

Attempts to resize a given allocation to a new size. If the new size is smaller, the start index remains unchanged.

TryGetAllocationRegion ( ulong allocationId, Allocation &allocation ) : bool

Gets the allocation region associated with the given allocation id if it is present.

Private Methods

Method Description
AddAllocation ( ulong id, long start, long end, Allocation &allocation, Allocation &nextAllocation ) : void
Contains ( ulong id ) : bool
ValidatePointers ( ) : void

Method Details

Allocate() public method

Attempts to allocate a range of memory.
public Allocate ( ulong id, long size, long &outputStart ) : bool
id ulong Unique id of the memory to allocate.
size long Size of the memory to allocate.
outputStart long Starting index of the allocated memory, if successful.
return bool

Allocator() public method

Creates a new memory pool.
public Allocator ( long memoryPoolSize, BufferPool idBufferPool = null, BufferPool allocationBufferPool = null, BufferPool tableBufferPool = null ) : System
memoryPoolSize long Size of the pool in elements.
idBufferPool BufferPool Buffer pool to use in the allocator. If null, the allocator picks.
allocationBufferPool BufferPool Buffer pool to use in the allocator. If null, the allocator picks.
tableBufferPool BufferPool Buffer pool to use in the allocator. If null, the allocator picks.
return System

CanFit() public method

Checks if a block of memory can fit into the current state of the allocator.
public CanFit ( long size, QuickList ignoredIds = null ) : bool
size long Size of the memory to test.
ignoredIds QuickList Ids of allocations to treat as nonexistent for the purposes of the test.
return bool

Deallocate() public method

Removes the memory associated with the id from the pool.
public Deallocate ( ulong id ) : bool
id ulong Id to remove.
return bool

GetLargestContiguousSize() public method

Gets the size of the largest contiguous area and the total free space in the allocator. Not very efficient; runs in linear time for the number of allocations.
public GetLargestContiguousSize ( long &largestContiguous, long &totalFreeSpace ) : void
largestContiguous long Largest contiguous region in the allocator. The allocator can hold an allocation up to this size.
totalFreeSpace long Total free space in the allocator.
return void

IncrementalCompact() public method

Finds the first allocation with empty space before it and pulls it forward to close the gap. Assumes the ability to perform synchronous reallocation.
public IncrementalCompact ( ulong &id, long &size, long &oldStart, long &newStart ) : bool
id ulong Id of the allocation to be moved, if any.
size long Size of the moved allocation.
oldStart long Old starting location of the allocation.
newStart long New starting location of the allocation.
return bool

Resize() public method

Attempts to resize a given allocation to a new size. If the new size is smaller, the start index remains unchanged.
public Resize ( ulong id, long size, long &oldStart, long &newStart ) : bool
id ulong Id of the allocation to resize.
size long New desired size of the allocation.
oldStart long Old start location of the allocation.
newStart long New start location of the allocation.
return bool

TryGetAllocationRegion() public method

Gets the allocation region associated with the given allocation id if it is present.
public TryGetAllocationRegion ( ulong allocationId, Allocation &allocation ) : bool
allocationId ulong Allocation id to look up the allocation for.
allocation Allocation Allocation associated with the id, if present.
return bool