public AtomicNativeBags(Allocator allocator) { _allocator = allocator; _threadsCount = JobsUtility.MaxJobThreadCount + 1; var bufferSize = MemoryUtilities.SizeOf <NativeBag>(); var bufferCount = _threadsCount; var allocationSize = bufferSize * bufferCount; var ptr = (byte *)MemoryUtilities.Alloc((uint)allocationSize, allocator); MemoryUtilities.MemClear((IntPtr)ptr, (uint)allocationSize); for (int i = 0; i < bufferCount; i++) { var bufferPtr = (NativeBag *)(ptr + bufferSize * i); var buffer = new NativeBag(allocator); MemoryUtilities.CopyStructureToPtr(ref buffer, (IntPtr)bufferPtr); } _data = (NativeBag *)ptr; }