コード例 #1
0
ファイル: Bitstream.cs プロジェクト: zxf1178649100/FPSSample
        public BitStream(int length, Allocator allocator)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (length > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException("length", string.Format("Length * sizeof(T) cannot exceed {0} bytes", int.MaxValue));
            }
#endif
            m_Length             = length;
            m_BitCount           = length * 8;
            m_Allocator          = allocator;
            m_WriteScratchBuffer = 0;
            m_WriteBitIndex      = 0;
            m_WriteByteIndex     = 0;

            m_Buffer = (byte *)UnsafeUtility.Malloc(length, UnsafeUtility.AlignOf <byte>(), m_Allocator);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_MinIndex = 0;
            m_MaxIndex = length - 1;
#if UNITY_2018_3_OR_NEWER
            DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 1, m_Allocator);
#else
            DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 1);
#endif
            m_NakedPtrSafety = new NakedPtrSafety();
            AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;
#endif
        }
コード例 #2
0
ファイル: Bitstream.cs プロジェクト: zxf1178649100/FPSSample
        public BitStream(byte[] data, Allocator allocator, int size = -1)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (data == null)
            {
                throw new ArgumentException("Data can not be null.", "data");
            }
#endif
            int dataLength = data.Length;
            if (size != -1)
            {
                dataLength = size;
            }

            void *buffer = UnsafeUtility.Malloc(dataLength, UnsafeUtility.AlignOf <byte>(), allocator);

            fixed(byte *fixedBuffer = data)
            {
                UnsafeUtility.MemCpy(buffer, fixedBuffer, dataLength);
            }

            m_Buffer             = (byte *)buffer;
            m_Length             = dataLength;
            m_BitCount           = m_Length * 8;
            m_Allocator          = allocator;
            m_WriteScratchBuffer = 0;
            m_WriteBitIndex      = 0;
            m_WriteByteIndex     = dataLength;

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_MinIndex = 0;
            m_MaxIndex = m_Length - 1;
#if UNITY_2018_3_OR_NEWER
            DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 1, m_Allocator);
#else
            DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 1);
#endif
            m_NakedPtrSafety = new NakedPtrSafety();
            AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;
#endif
        }