When should I use which value (None, Invalid, Temp, TempJob, Persistent, FirstUserIndex, AudioKernal)
How does each Allocator affect allocation and the lifespan of the NativeArray in implementation?
I can't figure out how the lifespans/implementations differ for each Allocator value when instantiating a NativeArray. I've checked the docs and IntelliSense to no avail, besides being shown which Enum values are available.
Allocator.TempOffers fastest allocation time. Is valid for a single frame. No need to call
Dispose(). Can't be assigned to field of a job struct (because job's lifetime can be over 1 frame) but can be allocated by a job execution code.Allocator.TempJobFast, temporary allocations for job struct fields.
Allocator.PersistentSlow allocation. No lifetime restrictions. Must call
Dispose()to free (memory leak otherwise). Ideal for data that needs to always exist for a system to function.Allocator.NoneAllocator.Noneis for these rare cases where you need to say "no allocation happened here" to create a validNativeArrayof which lifetime is decided elsewhere. For example, to access managed memory as if it is just anotherNativeArray:source: https://gist.github.com/andrew-raphael-lukasik/812e152f95e38cc13c44e5040c5739bc
InvalidSignals allocation failure. Don't use.
FirstUserIndexNo idea. Don't use.
AudioKernelNo idea. Don't use.