/// <summary>
 /// Begin reading data at the iteration index.
 /// </summary>
 /// <param name="foreachIndex"></param>
 /// <remarks>BeginForEachIndex must always be called balanced by a EndForEachIndex.</remarks>
 public void BeginForEachIndex(int foreachIndex)
 {
     this.MForeachIndex    = foreachIndex;
     this._mElementCount   = 0;
     this._mNumberOfBlocks = 0;
     this._mFirstBlock     = this._mCurrentBlock;
     this._mFirstOffset    = (int)(this._mCurrentPtr - (byte *)this._mCurrentBlock);
 }
 internal Reader(ref UnsafeEventStream stream)
 {
     this.MBlockStream        = stream._blockData;
     this.MCurrentBlock       = null;
     this.MCurrentPtr         = null;
     this.MCurrentBlockEnd    = null;
     this.MRemainingItemCount = 0;
     this.MLastBlockSize      = 0;
 }
            /// <summary>
            /// Begin reading data at the iteration index.
            /// </summary>
            /// <param name="foreachIndex"></param>
            /// <remarks>BeginForEachIndex must always be called balanced by a EndForEachIndex.</remarks>
            /// <returns>The number of elements at this index.</returns>
            public int BeginForEachIndex(int foreachIndex)
            {
                this.MRemainingItemCount = MBlockStream->Ranges[foreachIndex].ElementCount;
                this.MLastBlockSize      = MBlockStream->Ranges[foreachIndex].LastOffset;

                this.MCurrentBlock    = MBlockStream->Ranges[foreachIndex].Block;
                this.MCurrentPtr      = (byte *)this.MCurrentBlock + MBlockStream->Ranges[foreachIndex].OffsetInFirstBlock;
                this.MCurrentBlockEnd = (byte *)this.MCurrentBlock + UnsafeEventStreamBlockData.AllocationSize;

                return(this.MRemainingItemCount);
            }
 internal IndexWriter(ref UnsafeEventStream stream)
 {
     this.MBlockStream      = stream._blockData;
     this.MForeachIndex     = int.MinValue;
     this._mElementCount    = -1;
     this._mCurrentBlock    = null;
     this._mCurrentBlockEnd = null;
     this._mCurrentPtr      = null;
     this._mFirstBlock      = null;
     this._mNumberOfBlocks  = 0;
     this._mFirstOffset     = 0;
     this._mThreadIndex     = 0;
 }
            /// <summary>
            /// Returns pointer to data.
            /// </summary>
            /// <param name="size">Size in bytes.</param>
            /// <returns>Pointer to data.</returns>
            public byte *ReadUnsafePtr(int size)
            {
                this.MRemainingItemCount--;

                byte *ptr = this.MCurrentPtr;

                this.MCurrentPtr += size;

                if (this.MCurrentPtr > this.MCurrentBlockEnd)
                {
                    this.MCurrentBlock = MCurrentBlock->Next;
                    this.MCurrentPtr   = MCurrentBlock->Data;

                    this.MCurrentBlockEnd = (byte *)this.MCurrentBlock + UnsafeEventStreamBlockData.AllocationSize;

                    ptr = this.MCurrentPtr;
                    this.MCurrentPtr += size;
                }

                return(ptr);
            }
        internal UnsafeEventStreamBlock *Allocate(UnsafeEventStreamBlock *oldBlock, int threadIndex)
        {
            Assert.IsTrue(threadIndex < this.BlockCount && threadIndex >= 0);

            var block = (UnsafeEventStreamBlock *)UnsafeUtility.Malloc(AllocationSize, 16, this.Allocator);

            block->Next = null;

            if (oldBlock == null)
            {
                // Append our new block in front of the previous head.
                block->Next = this.Blocks[threadIndex];
                this.Blocks[threadIndex] = block;
            }
            else
            {
                oldBlock->Next = block;
            }

            return(block);
        }
Example #7
0
        private void Deallocate()
        {
            if (this._blockData == null)
            {
                return;
            }

            for (int i = 0; i != _blockData->BlockCount; i++)
            {
                var block = this._blockData->Blocks[i];
                while (block != null)
                {
                    UnsafeEventStreamBlock *next = block->Next;
                    UnsafeUtility.Free(block, this._allocator);
                    block = next;
                }
            }

            UnsafeUtility.Free(this._blockData->Ranges, this._allocator);
            UnsafeUtility.Free(this._blockData->ThreadRanges, this._allocator);
            UnsafeUtility.Free(this._blockData, this._allocator);
            this._blockData = null;
            this._allocator = Allocator.None;
        }