Class CollectionHelper
Provides helper methods for collections.
Inheritance
CollectionHelper
Assembly: Unity.Collections.dll
Syntax
public static class CollectionHelper
Fields
CacheLineSize
The size in bytes of the current platform's L1 cache lines.
Declaration
public const int CacheLineSize = 64
Field Value
Type |
Description |
int |
The size in bytes of the current platform's L1 cache lines.
|
Methods
Align(int, int)
Returns an allocation size in bytes that factors in alignment.
Declaration
public static int Align(int size, int alignmentPowerOfTwo)
Parameters
Type |
Name |
Description |
int |
size |
The size to align.
|
int |
alignmentPowerOfTwo |
A non-zero, positive power of two.
|
Returns
Type |
Description |
int |
The smallest integer that is greater than or equal to size and is a multiple of alignmentPowerOfTwo .
|
Examples
int size = CollectionHelper.Align(55, 16);
Exceptions
Type |
Condition |
ArgumentException |
Thrown if alignmentPowerOfTwo is not a non-zero, positive power of two.
|
Align(ulong, ulong)
Returns an allocation size in bytes that factors in alignment.
Declaration
public static ulong Align(ulong size, ulong alignmentPowerOfTwo)
Parameters
Type |
Name |
Description |
ulong |
size |
The size to align.
|
ulong |
alignmentPowerOfTwo |
A non-zero, positive power of two.
|
Returns
Type |
Description |
ulong |
The smallest integer that is greater than or equal to size and is a multiple of alignmentPowerOfTwo .
|
Examples
ulong size = CollectionHelper.Align(55, 16);
Exceptions
Type |
Condition |
ArgumentException |
Thrown if alignmentPowerOfTwo is not a non-zero, positive power of two.
|
CreateNativeArray<T>(int, AllocatorHandle, NativeArrayOptions)
Declaration
public static NativeArray<T> CreateNativeArray<T>(int length, AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory) where T : struct
Parameters
Returns
Type Parameters
CreateNativeArray<T>(NativeArray<T>, AllocatorHandle)
Declaration
public static NativeArray<T> CreateNativeArray<T>(NativeArray<T> array, AllocatorManager.AllocatorHandle allocator) where T : struct
Parameters
Returns
Type Parameters
CreateNativeArray<T>(T[], AllocatorHandle)
Declaration
public static NativeArray<T> CreateNativeArray<T>(T[] array, AllocatorManager.AllocatorHandle allocator) where T : struct
Parameters
Returns
Type Parameters
CreateNativeArray<T, U>(int, ref U, NativeArrayOptions)
Declaration
public static NativeArray<T> CreateNativeArray<T, U>(int length, ref U allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory) where T : struct where U : unmanaged, AllocatorManager.IAllocator
Parameters
Returns
Type Parameters
CreateNativeArray<T, U>(T[], ref U)
Declaration
public static NativeArray<T> CreateNativeArray<T, U>(T[] array, ref U allocator) where T : struct where U : unmanaged, AllocatorManager.IAllocator
Parameters
Type |
Name |
Description |
T[] |
array |
|
U |
allocator |
|
Returns
Type Parameters
CreateNativeMultiHashMap<TKey, TValue, U>(int, ref U)
Declaration
public static NativeMultiHashMap<TKey, TValue> CreateNativeMultiHashMap<TKey, TValue, U>(int length, ref U allocator) where TKey : struct, IEquatable<TKey> where TValue : struct where U : unmanaged, AllocatorManager.IAllocator
Parameters
Type |
Name |
Description |
int |
length |
|
U |
allocator |
|
Returns
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
U |
|
Hash(void*, int)
Returns a (non-cryptographic) hash of a memory block.
Declaration
public static uint Hash(void* ptr, int bytes)
Parameters
Type |
Name |
Description |
void* |
ptr |
A buffer.
|
int |
bytes |
The number of bytes to hash.
|
Returns
Type |
Description |
uint |
A hash of the bytes.
|
IsAligned(ulong, int)
Returns true if an offset has a given alignment.
Declaration
public static bool IsAligned(ulong offset, int alignmentPowerOfTwo)
Parameters
Type |
Name |
Description |
ulong |
offset |
An offset
|
int |
alignmentPowerOfTwo |
A non-zero, positive power of two.
|
Returns
Type |
Description |
bool |
True if the offset is a multiple of alignmentPowerOfTwo .
|
Exceptions
Type |
Condition |
ArgumentException |
Thrown if alignmentPowerOfTwo is not a non-zero, positive power of two.
|
IsAligned(void*, int)
Returns true if the address represented by the pointer has a given alignment.
Declaration
public static bool IsAligned(void* p, int alignmentPowerOfTwo)
Parameters
Type |
Name |
Description |
void* |
p |
The pointer.
|
int |
alignmentPowerOfTwo |
A non-zero, positive power of two.
|
Returns
Type |
Description |
bool |
True if the address is a multiple of alignmentPowerOfTwo .
|
Exceptions
Type |
Condition |
ArgumentException |
Thrown if alignmentPowerOfTwo is not a non-zero, positive power of two.
|
IsPowerOfTwo(int)
Returns true if a positive value is a non-zero power of two.
Declaration
public static bool IsPowerOfTwo(int value)
Parameters
Type |
Name |
Description |
int |
value |
A positive value.
|
Returns
Type |
Description |
bool |
True if the value is a non-zero, positive power of two.
|
Log2Ceil(int)
Returns the binary logarithm of the value
, but the result is rounded up to the nearest integer.
Declaration
public static int Log2Ceil(int value)
Parameters
Type |
Name |
Description |
int |
value |
The value.
|
Returns
Type |
Description |
int |
The binary logarithm of the value , but the result is rounded up to the nearest integer.
|
Log2Floor(int)
Returns the binary logarithm of the value
, but the result is rounded down to the nearest integer.
Declaration
public static int Log2Floor(int value)
Parameters
Type |
Name |
Description |
int |
value |
The value.
|
Returns
Type |
Description |
int |
The binary logarithm of the value , but the result is rounded down to the nearest integer.
|
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.