C# Class ServerToolkit.BufferManagement.MemorySlab

Represents a large fixed-length memory block where smaller variable-length memory blocks are dynamically allocated
Inheritance: IMemorySlab
显示文件 Open project: tenor/ServerToolkit Class Usage Examples

Public Methods

Method Description
Free ( IMemoryBlock allocatedBlock ) : void

Frees an allocated memory block.

This method does not verify if the allocatedBlock is indeed from this slab. Callers should make sure that the allocatedblock belongs to the right slab.

TryAllocate ( long length, IMemoryBlock &allocatedBlock ) : bool

Attempts to allocate a memory block of a specified length.

TryAllocate ( long minLength, long maxLength, IMemoryBlock &allocatedBlock ) : long

Attempts to allocate a memory block of length between minLength and maxLength (both inclusive)

This overload is useful when multiple threads are concurrently working on the slab and the caller wants to allocate a block up to a desired size

Private Methods

Method Description
AddFreeBlock ( long offset, long length, bool suppressSetLargest ) : void

Marks an allocated block as unallocated

Set suppressSetLargest when the caller will the LargestFreeBlockSize after this method is called

GetLargest ( ) : long
MemorySlab ( long size, BufferPool pool ) : System

Initializes a new instance of the MemorySlab class

RemoveFreeBlock ( FreeSpace block, bool suppressSetLargest ) : void

Marks an unallocated contiguous block as allocated

Set suppressSetLargest when the caller will the LargestFreeBlockSize after this method is called

SetLargest ( long value ) : void

Sets a new value as the largest unallocated contiguous block size

ShrinkFreeMemoryBlock ( FreeSpace block, long shrinkTo ) : void

Marks an unallocated contiguous block as allocated, and then marks an allocated block as unallocated

ShrinkOrRemoveFreeMemoryBlock ( FreeSpace block, long shrinkTo, bool suppressSetLargest ) : void

Marks an unallocated contiguous block as allocated, and then marks an allocated block as unallocated

Set suppressSetLargest when the caller will the LargestFreeBlockSize after this method is calledDo not call this method directly, instead call ShrinkFreeMemoryBlock() or the FreeMemoryBlock()

Method Details

Free() public method

Frees an allocated memory block.
This method does not verify if the allocatedBlock is indeed from this slab. Callers should make sure that the allocatedblock belongs to the right slab.
public Free ( IMemoryBlock allocatedBlock ) : void
allocatedBlock IMemoryBlock Allocated memory block to be freed
return void

TryAllocate() public method

Attempts to allocate a memory block of a specified length.
public TryAllocate ( long length, IMemoryBlock &allocatedBlock ) : bool
length long Length, in bytes, of memory block
allocatedBlock IMemoryBlock Allocated memory block
return bool

TryAllocate() public method

Attempts to allocate a memory block of length between minLength and maxLength (both inclusive)
This overload is useful when multiple threads are concurrently working on the slab and the caller wants to allocate a block up to a desired size
public TryAllocate ( long minLength, long maxLength, IMemoryBlock &allocatedBlock ) : long
minLength long The minimum acceptable length
maxLength long The maximum acceptable length
allocatedBlock IMemoryBlock Allocated memory block
return long