Class Utilities
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
intSize of the buffer to allocate.
clearValue
byteDefault value used to clear the buffer.
align
intAlignment, 16 bytes by default.
Returns
- IntPtr
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
intSize of the buffer to allocate.
align
intAlignment, a positive value which is a power of 2. 16 bytes by default.
Returns
- IntPtr
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)
public static TimeSpan ConvertRawToTimestamp(long delta)
Parameters
delta
longThe delta.
Returns
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
TThe disposable.
Type Parameters
T
FreeMemory(nint)
Free an aligned memory buffer.
public static void FreeMemory(nint alignedBuffer)
Parameters
alignedBuffer
IntPtr
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
IEnumerableAn enumerator.
Returns
- int
Hashcode for the list.
GetHashCode(IEnumerator)
Computes a hashcode for an enumeration
public static int GetHashCode(IEnumerator it)
Parameters
it
IEnumeratorAn 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
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
TThe 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
Streaminput 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
TThe left value.
right
TThe right value.
Type Parameters
T
Type of a data to swap.