Exemplo n.º 1
0
        public void Dispose()
        {
            if (_data == null)
            {
                throw new Exception("using invalid AtomicNativeBags");
            }

            for (int i = 0; i < _threadsCount; i++)
            {
                GetBuffer(i).Dispose();
            }
            MemoryUtilities.Free((IntPtr)_data, _allocator);
            _data = null;
        }
        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;
        }