コード例 #1
0
            public void Execute(int index)
            {
                index += StartIndex;

                BinaryTokens[index] = new BinaryToken
                {
                    HandleIndex = index
                };

                Handles[index] = new HandleData
                {
                    DataIndex   = index,
                    DataVersion = 1
                };
            }
コード例 #2
0
        /// <summary>
        /// Constructs a new instance of <see cref="PackedBinaryStream"/> using the given capacities.
        /// </summary>
        /// <param name="initialTokensCapacity">Initial number of tokens to allocate.</param>
        /// <param name="initialBufferCapacity">Initial buffer size to allocate.</param>
        /// <param name="label">Allocator to use for internal buffers.</param>
        public PackedBinaryStream(int initialTokensCapacity, int initialBufferCapacity, Allocator label)
        {
            m_Label = label;
            m_Data  = (PackedBinaryStreamData *)UnsafeUtility.Malloc(sizeof(PackedBinaryStreamData), UnsafeUtility.AlignOf <PackedBinaryStreamData>(), m_Label);
            UnsafeUtility.MemClear(m_Data, sizeof(PackedBinaryStreamData));

            // Allocate token and handle buffers.
            m_Data->Tokens         = (BinaryToken *)UnsafeUtility.Malloc(sizeof(BinaryToken) * initialTokensCapacity, UnsafeUtility.AlignOf <BinaryToken>(), m_Label);
            m_Data->Handles        = (HandleData *)UnsafeUtility.Malloc(sizeof(HandleData) * initialTokensCapacity, UnsafeUtility.AlignOf <HandleData>(), m_Label);
            m_Data->TokensCapacity = initialTokensCapacity;

            // Allocate string/primitive storage.
            m_Data->Buffer         = (byte *)UnsafeUtility.Malloc(sizeof(byte) * initialBufferCapacity, UnsafeUtility.AlignOf <byte>(), m_Label);
            m_Data->BufferCapacity = initialBufferCapacity;

            if (initialTokensCapacity < 128)
            {
                for (var i = 0; i < initialTokensCapacity; i++)
                {
                    m_Data->Tokens[i] = new BinaryToken
                    {
                        HandleIndex = i
                    };

                    m_Data->Handles[i] = new HandleData
                    {
                        DataIndex   = i,
                        DataVersion = 1
                    };
                }
            }
            else
            {
                // Initialize handles and tokens with the correct indices.
                new InitializeJob
                {
                    Handles      = m_Data->Handles,
                    BinaryTokens = m_Data->Tokens,
                    StartIndex   = 0
                }.Schedule(initialTokensCapacity, initialTokensCapacity).Complete();
            }

            m_Data->TokenNextIndex   = 0;
            m_Data->TokenParentIndex = -1;
            m_Data->BufferPosition   = 0;
        }