Struct AllocatorManager.Block
Represents an individual allocation within an allocator.
Namespace: Unity.Collections
Syntax
public struct Block : IDisposable
Remarks
A block consists of a Range plus metadata about the type of elements for which the block was allocated.
Fields
AllocatedItems
Number of items allocated for.
Declaration
public int AllocatedItems
Field Value
Type | Description |
---|---|
Int32 | Number of items allocated for. |
BytesPerItem
Number of bytes per item.
Declaration
public int BytesPerItem
Field Value
Type | Description |
---|---|
Int32 | Number of bytes per item. |
Log2Alignment
Log2 of the byte alignment.
Declaration
public byte Log2Alignment
Field Value
Type | Description |
---|---|
Byte | Log2 of the byte alignment. |
Remarks
The alignment must always be power of 2. Storing the alignment as its log2 helps enforces this.
Padding0
This field only exists to pad the Block
struct. Ignore it.
Declaration
public byte Padding0
Field Value
Type | Description |
---|---|
Byte | This field only exists to pad the |
Padding1
This field only exists to pad the Block
struct. Ignore it.
Declaration
public ushort Padding1
Field Value
Type | Description |
---|---|
UInt16 | This field only exists to pad the |
Padding2
This field only exists to pad the Block
struct. Ignore it.
Declaration
public uint Padding2
Field Value
Type | Description |
---|---|
UInt32 | This field only exists to pad the |
Range
The range of memory encompassed by this block.
Declaration
public AllocatorManager.Range Range
Field Value
Type | Description |
---|---|
AllocatorManager.Range | The range of memory encompassed by this block. |
Properties
Alignment
The alignment.
Declaration
public int Alignment { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The alignment. |
Remarks
Must be power of 2 that's greater than or equal to 0.
Set alignment before the allocation is made. Setting it after has no effect on the allocation.
AllocatedBytes
Number of bytes allocated for this block.
Declaration
public readonly long AllocatedBytes { get; }
Property Value
Type | Description |
---|---|
Int64 | Number of bytes allocated for this block. |
Remarks
The requested allocation size may be smaller. Any excess is due to alignment
Bytes
Number of bytes requested for this block.
Declaration
public readonly long Bytes { get; }
Property Value
Type | Description |
---|---|
Int64 | Number of bytes requested for this block. |
Remarks
The actual allocation size may be larger due to alignment.
Methods
Allocate()
Allocates this block.
Declaration
public void Allocate()
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if safety checks are enabled and the allocation fails. |
Dispose()
Deallocates this block.
Declaration
public void Dispose()
Remarks
Same as TryAllocate().
Free()
Frees the block.
Declaration
public void Free()
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if safety checks are enabled and the deallocation fails. |
TryAllocate()
Attempts to allocate this block.
Declaration
public int TryAllocate()
Returns
Type | Description |
---|---|
Int32 | 0 if successful. Otherwise, returns the error code from the allocator function. |
TryFree()
Attempts to free this block.
Declaration
public int TryFree()
Returns
Type | Description |
---|---|
Int32 | 0 if successful. Otherwise, returns the error code from the allocator function. |