Table of Contents

Class Utilities

Namespace
Stride.Core
Assembly
Stride.Core.dll

Utility class.

public static class Utilities
Inheritance
Utilities

Methods

AllocateClearedMemory(int, byte, int)

Allocate an aligned memory buffer and clear it with a specified value (0 by defaault).

public static nint AllocateClearedMemory(int sizeInBytes, byte clearValue = 0, int align = 16)

Parameters

sizeInBytes int

Size of the buffer to allocate.

clearValue byte

Default value used to clear the buffer.

align int

Alignment, 16 bytes by default.

Returns

nint

A pointer to a buffer aligned.

Remarks

To free this buffer, call FreeMemory(nint)

AllocateMemory(int, int)

Allocate an aligned memory buffer.

public static nint AllocateMemory(int sizeInBytes, int align = 16)

Parameters

sizeInBytes int

Size of the buffer to allocate.

align int

Alignment, a positive value which is a power of 2. 16 bytes by default.

Returns

nint

A pointer to a buffer aligned.

Remarks

To free this buffer, call FreeMemory(nint)

Compare<TKey, TValue>(SortedList<TKey, TValue>, SortedList<TKey, TValue>)

Compares two collection, element by elements.

public static bool Compare<TKey, TValue>(SortedList<TKey, TValue> first, SortedList<TKey, TValue> second)

Parameters

first SortedList<TKey, TValue>

The collection to compare from.

second SortedList<TKey, TValue>

The colllection to compare to.

Returns

bool

True if lists are identical (but not necessarily in the same order). False otherwise.

Type Parameters

TKey
TValue

Remarks

Concrete SortedList is favored over interface to avoid enumerator object allocation.

Compare<TKey, TValue>(IDictionary<TKey, TValue>, IDictionary<TKey, TValue>)

Compares two collection, element by elements.

public static bool Compare<TKey, TValue>(IDictionary<TKey, TValue> first, IDictionary<TKey, TValue> second)

Parameters

first IDictionary<TKey, TValue>

The collection to compare from.

second IDictionary<TKey, TValue>

The colllection to compare to.

Returns

bool

True if lists are identical (but no necessarely of the same time). False otherwise.

Type Parameters

TKey
TValue

ConvertRawToTimestamp(long)

Converts a Stopwatch raw time to a TimeSpan.

public static TimeSpan ConvertRawToTimestamp(long delta)

Parameters

delta long

The delta.

Returns

TimeSpan

The TimeSpan.

Dispose<T>(ref T)

If non-null, disposes the specified object and set it to null, otherwise do nothing.

public static void Dispose<T>(ref T disposable) where T : class, IDisposable

Parameters

disposable T

The disposable.

Type Parameters

T

FreeMemory(nint)

Free an aligned memory buffer.

public static void FreeMemory(nint alignedBuffer)

Parameters

alignedBuffer nint

Remarks

The buffer must have been allocated with AllocateMemory(int, int)

GetHashCode(IDictionary)

Computes a hashcode for a dictionary.

public static int GetHashCode(IDictionary dict)

Parameters

dict IDictionary

Returns

int

Hashcode for the list.

GetHashCode(IEnumerable)

Computes a hashcode for an enumeration

public static int GetHashCode(IEnumerable it)

Parameters

it IEnumerable

An enumerator.

Returns

int

Hashcode for the list.

GetHashCode(IEnumerator)

Computes a hashcode for an enumeration

public static int GetHashCode(IEnumerator it)

Parameters

it IEnumerator

An enumerator.

Returns

int

Hashcode for the list.

IsMemoryAligned(nint, int)

Determines whether the specified memory pointer is aligned in memory.

public static bool IsMemoryAligned(nint memoryPtr, int align = 16)

Parameters

memoryPtr nint

The memory pointer.

align int

The align.

Returns

bool

true if the specified memory pointer is aligned in memory; otherwise, false.

IterateTree<T>(T, Func<T, IEnumerable<T>>)

Linq assisted full tree iteration and collection in a single line. Warning, could be slow.

public static IEnumerable<T> IterateTree<T>(T root, Func<T, IEnumerable<T>> childrenF)

Parameters

root T

The root item

childrenF Func<T, IEnumerable<T>>

The function to retrieve a child

Returns

IEnumerable<T>

Type Parameters

T

The type to iterate.

ReadStream(Stream)

Read stream to a byte[] buffer

[Obsolete("Allocates. Read into the destination.")]
public static byte[] ReadStream(Stream stream)

Parameters

stream Stream

input stream

Returns

byte[]

a byte[] buffer

Swap<T>(ref T, ref T)

Swaps the value between two references.

public static void Swap<T>(ref T left, ref T right)

Parameters

left T

The left value.

right T

The right value.

Type Parameters

T

Type of a data to swap.