Photon Fusion 2.1.1

FusionUnsafe Class Reference

Utility methods for memory operations. More...

Static Public Member Functions

static void * Alloc (int size, int align=DefaultAlignment, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Allocates a block of memory. The return address is 8-aligned.
static T * Alloc< T > (int align=DefaultAlignment, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Allocates a block of memory. The return address is 8-aligned.
static void * AllocAndClear (int size, int align=DefaultAlignment, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Allocates a block of memory. The memory is 0-initialized. The return address is 8-aligned.
static T * AllocAndClear< T > (int align=DefaultAlignment, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Allocates a block of memory. The memory is 0-initialized. The return address is 8-aligned.
static void * AllocAndClearArray (int count, int elementSize, int align=DefaultAlignment, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Allocates a block of memory. The memory is 0-initialized. The return address is 8-aligned.
static T * AllocAndClearArray< T > (int count, int align=DefaultAlignment, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Allocates a block of memory. The memory is 0-initialized. The return address is 8-aligned.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (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 align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (int size0, int size1, int size2, int size3, out void *ptr0, out void *ptr1, out void *ptr2, out void *ptr3, int align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (int size0, int size1, int size2, out void *ptr0, out void *ptr1, out void *ptr2, int align=DefaultAlignment)
 Allocates a block of memory and clears it.
static int AllocAndClearBlock (int size0, int size1, out void *ptr0, out void *ptr1, int align=DefaultAlignment)
 Allocates a block of memory and clears it.
static T ** AllocAndClearPtrArray< T > (int capacity, int align=DefaultAlignment, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Allocates a block of memory. The memory is 0-initialized. The return address is 8-aligned.
static void Clear ([NotNull] void *ptr, int size)
 Clears a block of memory by setting it to zero.
static void Clear< T > (Span< T > span)
 Clears a block of memory by setting it to zero.
static int Compare ([NotNull] void *ptr1, [NotNull] void *ptr2, int size)
 Compares two blocks of memory.
static int Compare (nint ptr1, nint ptr2, nuint size)
 Compares two blocks of memory.
static void Copy ([NotNull] void *destination, [NotNull] void *source, int size)
 Copies a block of memory from one location to another.
static void Copy (nint destination, nint source, nuint size)
 Copies a block of memory from the source to the destination.
static void Copy< T > (Span< T > destination, ReadOnlySpan< T > source)
 Copy from source to destination, with CopyTo semantics: destination must be the same size or bigger than source. If source is smaller than destination the excess part of destination is not written to.
static void Copy< T > (Span< T > destination, T *source)
 Copies a block of memory from the source to the destination.
static void Copy< T > (T *destination, ReadOnlySpan< T > source)
 Copies a block of memory from the source to the destination.
static void CopyToExact< T > (Span< T > destination, ReadOnlySpan< T > source)
 Copy from source to destination, like CopyTo but source and destination must be the same size.
static void * Expand (void *buffer, int currentSize, int newSize, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Expands the allocated memory of the array of the type to a new size by copying the old contents and freeing the old memory.
static T * ExpandArray< T > (T *buffer, int currentSize, int newSize, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Expands the allocated memory of the array of the type to a new size by copying the old contents and freeing the old memory.
static T ** ExpandPtrArray< T > (T **buffer, int currentSize, int newSize, [CallerFilePath] string callerFilePath=null, [CallerLineNumber] int callerLineNumber=0)
 Expands the allocated memory of the array of the type to a new size by copying the old contents and freeing the old memory.
static void Free (ref void *ptr)
 Frees ptr . If it is null, nothing will happen.
static void Free (void *ptr)
 Frees ptr . If it is null, nothing will happen.
static void Free< T > (ref T **ptr)
 Frees ptr . If it is null, nothing will happen.
static void Free< T > (ref T *ptr)
 Frees ptr . If it is null, nothing will happen.
static int GetFieldOffset ([NotNull] System.Reflection.FieldInfo fi)
 Gets the offset of the specified field.
static FusionUnsafeAllocResult GetMemoryTrackingResult ()
 Get the memory tracking result.
static int GetWordCount (int stride, int wordSize)
 Returns the word count for stride and a given word size.
static bool IsAligned (nint value, int align=DefaultAlignment)
 Returns true if value is aligned.
static bool IsAligned (void *value, int align=DefaultAlignment)
 Returns true if value is aligned.
static int MakeAligned (int value)
 Returns value aligned according to .
static int MakeAligned (int value, int align)
 Returns value aligned according to align .
static nint MakeAligned (nint value, int align)
 Returns value aligned according to align .
static void Move ([NotNull] void *destination, [NotNull] void *source, int size)
 Moves a block of memory from the source to the destination.
static void Move (nint destination, nint source, nuint size)
 Moves a block of memory from the source to the destination.
static unsafe byte * ReferenceToPointer< T > (ref T obj)
 Converts a reference to an unmanaged type to a pointer.
static ref T ReinterpretBytes< T > (Span< byte > bytes)
static ref T ReinterpretWords< T > (Span< int > words)
static ref T ReinterpretWords< T > (Span< int > words, int offset)
static T Replace< T > (ref T a, T value)
 Replaces the value at x with value and returns the replaced value.
static T Replace< T > (T *a, T value)
 Replaces the value at x with value and returns the replaced value.
static void Set ([NotNull] void *ptr, byte value, int size)
 Initializes a block of memory with given value.
static void Set (nint ptr, byte value, nuint count)
 Initializes a block of memory with given value.
static void SetMemoryTrackingMode (FusionUnsafeTrackingMode mode)
static int SizeOf ([NotNull] Type t)
 Gets the size of the specified type.
static void Swap (void *a, void *b, int count)
 Swaps values between two locations in memory.
static void Swap< T > (ref T a, ref T b)
 Swaps values between two locations in memory.
static void Swap< T > (T *a, T *b)
 Swaps values between two locations in memory.
static bool TryFree (void *ptr)
 Attempts to free ptr . If null, will return false. If alloc tracking is enabled, will also return false for a pointer that has not been allocated by this class.
static bool TryFree (void *ptr, out FusionUnsafeAllocInfo allocInfo)
 Attempts to free ptr . If null, will return false. If alloc tracking is enabled, will also return false for a pointer that has not been allocated by this class.

Static Public Attributes

const int DefaultAlignment = 8
 The default alignment of allocated blocks.

Detailed Description

Utility methods for memory operations.

Member Function Documentation

◆ Copy()

void Copy ( [NotNull] void * destination,
[NotNull] void * source,
int size )
static

Copies a block of memory from one location to another.

Parameters
destinationDo not pass a nullptr, the destination to be copied to
sourceDo not pass a nullptr, the source to be copied from
sizeThe size of the data to be copied

◆ GetFieldOffset()

int GetFieldOffset ( [NotNull] 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.

◆ 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 

◆ SetMemoryTrackingMode()

void SetMemoryTrackingMode ( FusionUnsafeTrackingMode mode)
static
Parameters
mode

◆ SizeOf()

int SizeOf ( [NotNull] 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.