Photon Fusion 2.1.1

Native Class Reference

Native Memory Allocator. More...

Static Public Member Functions

static void * AlignPointer (void *pointer, int alignment)
 Aligns a pointer to a specified alignment.
static void ArrayClear< T > (T *ptr, int size)
 Clears a range of elements in an array by setting them to zero.
static int ArrayCompare< T > (T *ptr1, T *ptr2, int size)
 Compares two arrays for equality.
static void ArrayCopy (void *source, int sourceIndex, void *destination, int destinationIndex, int count, int elementStride)
 Copies a range of elements from one array to another.
static int CopyFromArray< T > (void *destination, T[] source)
 Copies elements from a managed array to an unmanaged memory location.
static int CopyToArray< T > (T[] destination, void *source)
 Copies elements from an unmanaged memory location to a managed array.
static T * DoubleArray< T > (T *array, int currentLength)
 Doubles the size of an array by expanding it to twice its current length.
static T ** DoublePtrArray< T > (T **array, int currentLength)
 Doubles the size of an array of pointers by expanding it to twice its current length.
static T Empty< T > ()
 Returns an empty instance of the specified unmanaged type.
static void * Expand (void *buffer, int currentSize, int newSize)
 Expands a buffer to a new specified size.
static T * ExpandArray< T > (T *array, int currentLength, int newLength)
 Expands an array to a new specified length.
static T ** ExpandPtrArray< T > (T **array, int currentLength, int newLength)
 Expands an array of pointers to a new specified length.
static void Free (ref UniquePtr memory)
 Frees a block of memory.
static void Free (ref void *memory)
 Frees a block of memory.
static void Free< T > (ref T **memory)
 Frees a block of memory.
static void Free< T > (ref T *memory)
 Frees a block of memory.
static int GetAlignment (int stride)
 Gets the alignment of the specified stride.
static int GetAlignment< T > ()
 Gets the alignment of the specified unmanaged type.
static int GetFieldOffset (System.Reflection.FieldInfo fi)
 Gets the offset of the specified field.
static int GetLengthPrefixedUTF8ByteCount (string str)
 Gets the byte count of a UTF-8 encoded string with a length prefix.
static int GetMaxAlignment (int a, int b)
 Gets the maximum alignment of two given strides.
static int GetMaxAlignment (int a, int b, int c)
 Gets the maximum alignment of three given strides.
static int GetMaxAlignment (int a, int b, int c, int d)
 Gets the maximum alignment of four given strides.
static int GetMaxAlignment (int a, int b, int c, int d, int e)
 Gets the maximum alignment of five given strides.
static bool IsAligned (int stride, int alignment)
 Checks if a stride is aligned to a specified alignment.
static bool IsPointerAligned (void *pointer, int alignment)
 Checks if a pointer is aligned to a specified alignment.
static void * Malloc (int size)
 Allocates a block of memory.
static T * Malloc< T > ()
 Allocates a block of memory for a specified type.
static void * MallocAndClear (int size)
 Allocates and clears a block of memory.
static T * MallocAndClear< T > ()
 Allocates and clears a block of memory for a specified type.
static void * MallocAndClearArray (int stride, int length)
 Allocates and clears an array of memory blocks.
static T * MallocAndClearArray< T > (int length)
 Allocates and clears an array of memory blocks for a specified type.
static T * MallocAndClearArrayMin1< T > (int length)
 Allocates and clears an array of memory blocks for a specified type, ensuring a minimum length of 1.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, int size5, int size6, int size7, int size8, int size9, int size10, int size11, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, out void *ptr5, out void *ptr6, out void *ptr7, out void *ptr8, out void *ptr9, out void *ptr10, out void *ptr11, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, int size5, int size6, int size7, int size8, int size9, int size10, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, out void *ptr5, out void *ptr6, out void *ptr7, out void *ptr8, out void *ptr9, out void *ptr10, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, int size5, int size6, int size7, int size8, int size9, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, out void *ptr5, out void *ptr6, out void *ptr7, out void *ptr8, out void *ptr9, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, int size5, int size6, int size7, int size8, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, out void *ptr5, out void *ptr6, out void *ptr7, out void *ptr8, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, int size5, int size6, int size7, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, out void *ptr5, out void *ptr6, out void *ptr7, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, int size5, int size6, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, out void *ptr5, out void *ptr6, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, int size5, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, out void *ptr5, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, int size4, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, out void *ptr4, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, int size3, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, int size2, out void *ptr0, out void *ptr1, out void *ptr2, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static int MallocAndClearBlock (int size0, int size1, out void *ptr0, out void *ptr1, int alignment=ALIGNMENT)
 Allocates a block of memory and clears it.
static T ** MallocAndClearPtrArray< T > (int length)
 Allocates and clears an array of pointers for a specified type.
static T ** MallocAndClearPtrArrayMin1< T > (int length)
 Allocates and clears an array of pointers for a specified type, ensuring a minimum length of 1.
static void MemClear (void *ptr, int size)
 Clears a block of memory by setting it to zero.
static int MemCmp (void *ptr1, void *ptr2, int size)
 Compares two blocks of memory.
static void MemCpy (void *destination, void *source, int size)
 Copies a block of memory from the source to the destination.
static void MemCpyFast (void *d, void *s, int size)
 Copies memory quickly for specific sizes.
static void MemMove (void *destination, void *source, int size)
 Moves a block of memory from the source to the destination.
static int ReadLengthPrefixedUTF8 (void *source, out string result)
 Reads a length-prefixed UTF-8 encoded string from a memory location.
static unsafe byte * ReferenceToPointer< T > (ref T obj)
 Converts a reference to an unmanaged type to a pointer.
static int RoundBitsUpTo32 (int bits)
 Rounds the given number of bits up to the nearest multiple of 32.
static int RoundBitsUpTo64 (int bits)
 Rounds the given number of bits up to the nearest multiple of 64.
static int RoundToAlignment (int stride, int alignment)
 Rounds a stride to a specified alignment.
static long RoundToAlignment (long stride, int alignment)
 Rounds a stride to a specified alignment.
static int RoundToMaxAlignment (int stride)
 Rounds a stride to the maximum alignment.
static int SizeOf (Type t)
 Gets the size of the specified type.
static void ValidateBlockSentinels (IntPtr memory, int size)
 Validates the block sentinels to ensure memory integrity.
static int WordCount (int stride, int wordSize)
 Calculates the word count for a given stride and word size.
static int WriteLengthPrefixedUTF8 (void *destination, string str)
 Writes a length-prefixed UTF-8 encoded string to a memory location.

Static Public Attributes

const int ALIGNMENT = 8
 The alignment size in bytes.
const int CACHE_LINE_SIZE = 64
 The size of the cache line in bytes.

Detailed Description

Native Memory Allocator.

Member Function Documentation

◆ AlignPointer()

void * AlignPointer ( void * pointer,
int alignment )
static

Aligns a pointer to a specified alignment.

Parameters
pointerThe pointer to align.
alignmentThe alignment to apply.
Returns
The aligned pointer.

◆ ArrayClear< T >()

void ArrayClear< T > ( T * ptr,
int size )
static

Clears a range of elements in an array by setting them to zero.

Template Parameters
TThe type of the elements in the array.
Parameters
ptrThe pointer to the array.
sizeThe number of elements to clear.
Type Constraints
T :unmanaged 

◆ ArrayCompare< T >()

int ArrayCompare< T > ( T * ptr1,
T * ptr2,
int size )
static

Compares two arrays for equality.

Template Parameters
TThe type of the elements in the arrays.
Parameters
ptr1The pointer to the first array.
ptr2The pointer to the second array.
sizeThe number of elements to compare.
Returns
An integer that indicates the relative order of the arrays being compared.
Type Constraints
T :unmanaged 

◆ ArrayCopy()

void ArrayCopy ( void * source,
int sourceIndex,
void * destination,
int destinationIndex,
int count,
int elementStride )
static

Copies a range of elements from one array to another.

Parameters
sourceThe source array pointer.
sourceIndexThe zero-based index in the source array at which copying begins.
destinationThe destination array pointer.
destinationIndexThe zero-based index in the destination array at which storing begins.
countThe number of elements to copy.
elementStrideThe size of each element in bytes.

◆ CopyFromArray< T >()

int CopyFromArray< T > ( void * destination,
T[] source )
static

Copies elements from a managed array to an unmanaged memory location.

Template Parameters
TThe type of the elements in the array.
Parameters
destinationThe destination pointer.
sourceThe source array.
Returns
The number of bytes copied.
Type Constraints
T :unmanaged 

◆ CopyToArray< T >()

int CopyToArray< T > ( T[] destination,
void * source )
static

Copies elements from an unmanaged memory location to a managed array.

Template Parameters
TThe type of the elements in the array.
Parameters
destinationThe destination array.
sourceThe source pointer.
Returns
The number of bytes copied.
Type Constraints
T :unmanaged 

◆ DoubleArray< T >()

T * DoubleArray< T > ( T * array,
int currentLength )
static

Doubles the size of an array by expanding it to twice its current length.

Template Parameters
TThe type of the elements in the array.
Parameters
arrayThe pointer to the array to double.
currentLengthThe current length of the array.
Returns
A pointer to the new array with doubled size.
Type Constraints
T :unmanaged 

◆ DoublePtrArray< T >()

T ** DoublePtrArray< T > ( T ** array,
int currentLength )
static

Doubles the size of an array of pointers by expanding it to twice its current length.

Template Parameters
TThe type of the elements in the array.
Parameters
arrayThe pointer to the array of pointers to double.
currentLengthThe current length of the array.
Returns
A pointer to the new array of pointers with doubled size.
Type Constraints
T :unmanaged 

◆ Empty< T >()

T Empty< T > ( )
static

Returns an empty instance of the specified unmanaged type.

Template Parameters
TThe type of the instance to return.
Returns
An empty instance of the specified type.
Type Constraints
T :unmanaged 

◆ Expand()

void * Expand ( void * buffer,
int currentSize,
int newSize )
static

Expands a buffer to a new specified size.

Parameters
bufferThe pointer to the buffer to expand.
currentSizeThe current size of the buffer.
newSizeThe new size of the buffer.
Returns
A pointer to the new expanded buffer.

◆ ExpandArray< T >()

T * ExpandArray< T > ( T * array,
int currentLength,
int newLength )
static

Expands an array to a new specified length.

Template Parameters
TThe type of the elements in the array.
Parameters
arrayThe pointer to the array to expand.
currentLengthThe current length of the array.
newLengthThe new length of the array.
Returns
A pointer to the new expanded array.
Type Constraints
T :unmanaged 

◆ ExpandPtrArray< T >()

T ** ExpandPtrArray< T > ( T ** array,
int currentLength,
int newLength )
static

Expands an array of pointers to a new specified length.

Template Parameters
TThe type of the elements in the array.
Parameters
arrayThe pointer to the array of pointers to expand.
currentLengthThe current length of the array.
newLengthThe new length of the array.
Returns
A pointer to the new expanded array of pointers.
Type Constraints
T :unmanaged 

◆ Free() [1/2]

void Free ( ref UniquePtr memory)
static

Frees a block of memory.

Parameters
memoryThe pointer to the memory block to free.

◆ Free() [2/2]

void Free ( ref void * memory)
static

Frees a block of memory.

Parameters
memoryThe pointer to the memory block to free.

◆ Free< T >() [1/2]

void Free< T > ( ref T ** memory)
static

Frees a block of memory.

Parameters
memoryThe pointer to the memory block to free.
Type Constraints
T :unmanaged 

◆ Free< T >() [2/2]

void Free< T > ( ref T * memory)
static

Frees a block of memory.

Parameters
memoryThe pointer to the memory block to free.
Type Constraints
T :unmanaged 

◆ GetAlignment()

int GetAlignment ( int stride)
static

Gets the alignment of the specified stride.

Parameters
strideThe stride to get the alignment of.
Returns
The alignment of the specified stride.

◆ GetAlignment< T >()

int GetAlignment< T > ( )
static

Gets the alignment of the specified unmanaged type.

Template Parameters
TThe type to get the alignment of.
Returns
The alignment of the specified type.
Type Constraints
T :unmanaged 

◆ GetFieldOffset()

int GetFieldOffset ( System.Reflection.FieldInfo fi)
static

Gets the offset of the specified field.

Parameters
fiThe field information.
Returns
The offset of the specified field in bytes.

◆ GetLengthPrefixedUTF8ByteCount()

int GetLengthPrefixedUTF8ByteCount ( string str)
static

Gets the byte count of a UTF-8 encoded string with a length prefix.

Parameters
strThe string to encode.
Returns
The byte count of the encoded string with the length prefix.

◆ GetMaxAlignment() [1/4]

int GetMaxAlignment ( int a,
int b )
static

Gets the maximum alignment of two given strides.

Parameters
aThe first stride.
bThe second stride.
Returns
The maximum alignment of the two strides.

◆ GetMaxAlignment() [2/4]

int GetMaxAlignment ( int a,
int b,
int c )
static

Gets the maximum alignment of three given strides.

Parameters
aThe first stride.
bThe second stride.
cThe third stride.
Returns
The maximum alignment of the three strides.

◆ GetMaxAlignment() [3/4]

int GetMaxAlignment ( int a,
int b,
int c,
int d )
static

Gets the maximum alignment of four given strides.

Parameters
aThe first stride.
bThe second stride.
cThe third stride.
dThe fourth stride.
Returns
The maximum alignment of the four strides.

◆ GetMaxAlignment() [4/4]

int GetMaxAlignment ( int a,
int b,
int c,
int d,
int e )
static

Gets the maximum alignment of five given strides.

Parameters
aThe first stride.
bThe second stride.
cThe third stride.
dThe fourth stride.
eThe fifth stride.
Returns
The maximum alignment of the five strides.

◆ IsAligned()

bool IsAligned ( int stride,
int alignment )
static

Checks if a stride is aligned to a specified alignment.

Parameters
strideThe stride to check.
alignmentThe alignment to check against.
Returns
True if the stride is aligned, otherwise false.

◆ IsPointerAligned()

bool IsPointerAligned ( void * pointer,
int alignment )
static

Checks if a pointer is aligned to a specified alignment.

Parameters
pointerThe pointer to check.
alignmentThe alignment to check against.
Returns
True if the pointer is aligned, otherwise false.

◆ Malloc()

void * Malloc ( int size)
static

Allocates a block of memory.

Parameters
sizeThe number of bytes to allocate.
Returns
A pointer to the allocated memory block.
Exceptions
ExceptionThrown when the size is less than or equal to zero or exceeds the maximum allowed size.

◆ Malloc< T >()

T * Malloc< T > ( )
static

Allocates a block of memory for a specified type.

Template Parameters
TThe type of the memory block to allocate.
Returns
A pointer to the allocated memory block.
Type Constraints
T :unmanaged 

◆ MallocAndClear()

void * MallocAndClear ( int size)
static

Allocates and clears a block of memory.

Parameters
sizeThe number of bytes to allocate and clear.
Returns
A pointer to the allocated and cleared memory block.

◆ MallocAndClear< T >()

T * MallocAndClear< T > ( )
static

Allocates and clears a block of memory for a specified type.

Template Parameters
TThe type of the memory block to allocate and clear.
Returns
A pointer to the allocated and cleared memory block.
Type Constraints
T :unmanaged 

◆ MallocAndClearArray()

void * MallocAndClearArray ( int stride,
int length )
static

Allocates and clears an array of memory blocks.

Parameters
strideThe size of each element in the array.
lengthThe number of elements in the array.
Returns
A pointer to the allocated and cleared array of memory blocks.

◆ MallocAndClearArray< T >()

T * MallocAndClearArray< T > ( int length)
static

Allocates and clears an array of memory blocks for a specified type.

Template Parameters
TThe type of the elements in the array.
Parameters
lengthThe number of elements in the array.
Returns
A pointer to the allocated and cleared array of memory blocks.
Type Constraints
T :unmanaged 

◆ MallocAndClearArrayMin1< T >()

T * MallocAndClearArrayMin1< T > ( int length)
static

Allocates and clears an array of memory blocks for a specified type, ensuring a minimum length of 1.

Template Parameters
TThe type of the elements in the array.
Parameters
lengthThe number of elements in the array.
Returns
A pointer to the allocated and cleared array of memory blocks.
Type Constraints
T :unmanaged 

◆ MallocAndClearPtrArray< T >()

T ** MallocAndClearPtrArray< T > ( int length)
static

Allocates and clears an array of pointers for a specified type.

Template Parameters
TThe type of the elements in the array.
Parameters
lengthThe number of elements in the array.
Returns
A pointer to the allocated and cleared array of pointers.
Type Constraints
T :unmanaged 

◆ MallocAndClearPtrArrayMin1< T >()

T ** MallocAndClearPtrArrayMin1< T > ( int length)
static

Allocates and clears an array of pointers for a specified type, ensuring a minimum length of 1.

Template Parameters
TThe type of the elements in the array.
Parameters
lengthThe number of elements in the array.
Returns
A pointer to the allocated and cleared array of pointers.
Type Constraints
T :unmanaged 

◆ MemClear()

void MemClear ( void * ptr,
int size )
static

Clears a block of memory by setting it to zero.

Parameters
ptrThe pointer to the memory block.
sizeThe number of bytes to clear.

◆ MemCmp()

int MemCmp ( void * ptr1,
void * ptr2,
int size )
static

Compares two blocks of memory.

Parameters
ptr1The first memory block pointer.
ptr2The second memory block pointer.
sizeThe number of bytes to compare.
Returns
An integer that indicates the relative order of the memory blocks being compared.

◆ MemCpy()

void MemCpy ( void * destination,
void * source,
int size )
static

Copies a block of memory from the source to the destination.

Parameters
destinationThe destination pointer.
sourceThe source pointer.
sizeThe number of bytes to copy.

◆ MemCpyFast()

void MemCpyFast ( void * d,
void * s,
int size )
static

Copies memory quickly for specific sizes.

Parameters
dThe destination pointer.
sThe source pointer.
sizeThe number of bytes to copy.

◆ MemMove()

void MemMove ( void * destination,
void * source,
int size )
static

Moves a block of memory from the source to the destination.

Parameters
destinationThe destination pointer.
sourceThe source pointer.
sizeThe number of bytes to move.

◆ ReadLengthPrefixedUTF8()

int ReadLengthPrefixedUTF8 ( void * source,
out string result )
static

Reads a length-prefixed UTF-8 encoded string from a memory location.

Parameters
sourceThe source pointer.
resultThe resulting string.
Returns
The number of bytes read.

◆ ReferenceToPointer< T >()

unsafe byte * ReferenceToPointer< T > ( ref T obj)
static

Converts a reference to an unmanaged type to a pointer.

Template Parameters
TThe type of the object.
Parameters
objThe reference to the object.
Returns
A pointer to the object.
Type Constraints
T :unmanaged 

◆ RoundBitsUpTo32()

int RoundBitsUpTo32 ( int bits)
static

Rounds the given number of bits up to the nearest multiple of 32.

Parameters
bitsThe number of bits to round up.
Returns
The rounded number of bits.

◆ RoundBitsUpTo64()

int RoundBitsUpTo64 ( int bits)
static

Rounds the given number of bits up to the nearest multiple of 64.

Parameters
bitsThe number of bits to round up.
Returns
The rounded number of bits.

◆ RoundToAlignment() [1/2]

int RoundToAlignment ( int stride,
int alignment )
static

Rounds a stride to a specified alignment.

Parameters
strideThe stride to round.
alignmentThe alignment to apply.
Returns
The rounded stride.
Exceptions
InvalidOperationExceptionThrown when the alignment is invalid.

◆ RoundToAlignment() [2/2]

long RoundToAlignment ( long stride,
int alignment )
static

Rounds a stride to a specified alignment.

Parameters
strideThe stride to round.
alignmentThe alignment to apply.
Returns
The rounded stride.
Exceptions
InvalidOperationExceptionThrown when the alignment is invalid.

◆ RoundToMaxAlignment()

int RoundToMaxAlignment ( int stride)
static

Rounds a stride to the maximum alignment.

Parameters
strideThe stride to round.
Returns
The rounded stride.

◆ SizeOf()

int SizeOf ( Type t)
static

Gets the size of the specified type.

Parameters
tThe type to get the size of.
Returns
The size of the specified type in bytes.

◆ ValidateBlockSentinels()

void ValidateBlockSentinels ( IntPtr memory,
int size )
static

Validates the block sentinels to ensure memory integrity.

Parameters
memoryThe pointer to the memory block.
sizeThe size of the memory block.

◆ WordCount()

int WordCount ( int stride,
int wordSize )
static

Calculates the word count for a given stride and word size.

Parameters
strideThe stride to calculate.
wordSizeThe size of each word.
Returns
The word count.

◆ WriteLengthPrefixedUTF8()

int WriteLengthPrefixedUTF8 ( void * destination,
string str )
static

Writes a length-prefixed UTF-8 encoded string to a memory location.

Parameters
destinationThe destination pointer.
strThe string to encode and write.
Returns
The number of bytes written.