ECS 简略版说明七:Collection、Mathmatic

目录

Unity.Collections cheat sheet

Allocators

Array-like types

Map and set types

Bit arrays and bit fields

String types

Other types

Enumerators

Parallel readers and writers


Unity.Collections

Collections分为三类:

  • Unity.Collections 中以Native- 开头的都有一个 safety checks 以确保它们被正确地处理并以线程安全的方式使用。
  • Unity.Collections.LowLevel.Unsafe 下面的,以 Unsafe- 开头的不包含safety checks.
  • 其余的类型没有被 allocated and 不包含 pointers, so effectively their disposal and thread safety are never a concern. 这些类型只保存少量的数据。

Allocators

  • Allocator.Temp: The fastest allocator. For very short-lived allocations. Temp allocations cannot be passed into jobs.
  • Allocator.TempJob: The next fastest allocator. For short-lived allocations (4-frame lifetime). TempJob allocations can be passed into jobs.
  • Allocator.Persistent: The slowest allocator. For indefinite lifetime allocations. Persistent allocations can be passed into jobs.

Array-like types

类似于数组的类型有: Unity.Collections.NativeArray<T> and Unity.Collections.NativeSlice<T>.

NativeListA resizable list.
UnsafeListA resizable list.
UnsafePtrListA resizable list of pointers.
NativeStreamA set of append-only, untyped buffers.
UnsafeStreamA set of append-only, untyped buffers.
UnsafeAppendBufferAn append-only untyped buffer.
NativeQueueA resizable queue.
UnsafeRingQueueA fixed-size circular buffer.
FixedList32BytesA 32-byte list, including 2 bytes of overhead, so 30 bytes are available for storage. Max capacity depends upon the type parameter.
FixedList64BytesA 64-byte list, including 2 bytes of overhead, so 62 bytes are available for storage. Max capacity depends upon the type parameter.
FixedList128BytesA 128-byte list, including 2 bytes of overhead, so 126 bytes are available for storage. Max capacity depends upon the type parameter.
FixedList512BytesA 512-byte list, including 2 bytes of overhead, so 510 bytes are available for storage. Max capacity depends upon the type parameter.
FixedList4096BytesA 4096-byte list, including 2 bytes of overhead, so 4094 bytes are available for storage. Max capacity depends upon the type parameter.

没有多维数组类型,但是可以把多维转成一维,比如:for an int[4][5] array, use an int[20] array instead (because 4 * 5 is 20).

When using the Entities package, a DynamicBuffer component is often the best choice for an array- or list-like collection.

See also NativeArrayExtensionsListExtensionsNativeSortExtension.

Map and set types

NativeParallelHashMapAn unordered associative array of key-value pairs.
UnsafeParallelHashMapAn unordered associative array of key-value pairs.
NativeParallelHashSetA set of unique values.
UnsafeParallelHashSetA set of unique values.
NativeMultiHashMapAn unordered associative array of key-value pairs. The keys do not have to be unique, i.e. two pairs can have equal keys.
UnsafeMultiHashMapAn unordered associative array of key-value pairs. The keys do not have to be unique, i.e. two pairs can have equal keys.

See also HashSetExtensionsUnity.Collections.NotBurstCompatible.Extensions, and Unity.Collections.LowLevel.Unsafe.NotBurstCompatible.Extensions

Bit arrays and bit fields

BitField32A fixed-size array of 32 bits.
BitField64A fixed-size array of 64 bits.
NativeBitArrayAn arbitrary-sized array of bits.
UnsafeBitArrayAn arbitrary-sized array of bits.

String types

NativeTextA UTF-8 encoded string. Mutable and resizable.
FixedString32BytesA 32-byte UTF-8 encoded string, including 3 bytes of overhead, so 29 bytes available for storage.
FixedString64BytesA 64-byte UTF-8 encoded string, including 3 bytes of overhead, so 61 bytes available for storage.
FixedString128BytesA 128-byte UTF-8 encoded string, including 3 bytes of overhead, so 125 bytes available for storage.
FixedString512BytesA 512-byte UTF-8 encoded string, including 3 bytes of overhead, so 509 bytes available for storage.
FixedString4096BytesA 4096-byte UTF-8 encoded string, including 3 bytes of overhead, so 4093 bytes available for storage.

See also FixedString and FixedStringMethods.

Other types

NativeReferenceA reference to a single value. Functionally equivalent to an array of length 1.
UnsafeAtomicCounter32A 32-bit atomic counter.
UnsafeAtomicCounter64A 64-bit atomic counter.

Enumerators

Most of the collections have a GetEnumerator method, which returns an implementation of IEnumerator<T>. The enumerator's MoveNext method advances its Current property to the next element.

Parallel readers and writers

Several of the collection types have nested types for reading and writing from parallel jobs. For example, to write safely to a NativeList<T> from a parallel job, you need a NativeList<T>.ParallelWriter.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TO_ZRG

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值