public void BeginBatch()
 {
     Assert.IsTrue(currentChain == null, "Can not begin new batch write, when batch writing is started, Call EndBatch");
     Assert.IsTrue(ThreadID <= BlockChainCount, "Thread ID must be smaller than BlockChainCount");
     currentChain = BlockChains + ThreadID;
     currentBlock = currentChain->GetWritingBlock(allocator);
 }
        public UnsafeParallelBuffer(Allocator allocator)
        {
            this.mAllocator = allocator;
            var allocSize = UnsafeUtility.SizeOf <ThreadBlockChain>() * BlockChainCount;

            BlockChains = (ThreadBlockChain *)UnsafeUtility.Malloc(allocSize, JobsUtility.CacheLineSize, allocator);
            UnsafeUtility.MemClear(BlockChains, allocSize);
        }
 public void EndBatch()
 {
     Assert.IsTrue(currentChain != null, "Writing not started by calling BeginBatch, target batch is not defined");
     if (currentBlock->mDataByteLen > 0)
     {
         currentChain->mBlockUsed++;
     }
     //currentChain->mLastBlock = currentBlock;
     currentChain = null;
     currentBlock = null;
 }
        public JobHandle Dispose(JobHandle dependsOn)
        {
            dependsOn = new DisposeBlocksJob()
            {
                BlockChains = BlockChains,
                allocator   = mAllocator
            }.Schedule(BlockChainCount, 4, dependsOn);

            dependsOn = new DisposePointerJob()
            {
                BlockChains = BlockChains,
                allocator   = mAllocator
            }.Schedule(dependsOn);
            mAllocator  = Allocator.Invalid;
            BlockChains = null;
            return(dependsOn);
        }
 public void Dispose()
 {
     if (mAllocator.ShouldDeallocate())
     {
         for (int i = 0; i < BlockChainCount; i++)
         {
             var chain = (BlockChains + i);
             var block = chain->mFirstBlock;
             while (block != null)
             {
                 var next = block->mNextBlock;
                 UnsafeUtility.Free(block, mAllocator);
                 Assert.IsFalse(next == chain->mFirstBlock, "block loop!");
                 block = next;
             }
         }
         UnsafeUtility.Free(BlockChains, mAllocator);
     }
     mAllocator  = Allocator.Invalid;
     BlockChains = null;
 }