Ejemplo n.º 1
0
 public void Dispose()
 {
     if (!UnsafeUtility.IsValidAllocator(m_AllocatorLabel))
     {
         throw new InvalidOperationException("The NativeDataResource can not be Disposed because it was not allocated with a valid allocator.");
     }
     UnsafeUtility.Free(m_Data, m_AllocatorLabel);
     m_Data = null;
     UnsafeUtility.Free(m_Table, m_AllocatorLabel);
     m_Table = null;
     UnsafeUtility.Free(m_Index, m_AllocatorLabel);
     m_Index = null;
 }
Ejemplo n.º 2
0
        public AtomicFloatResource(int capacity, Allocator allocator)
        {
            Assert.IsTrue(UnsafeUtility.SizeOf <float>() <= 8);
            Assert.IsTrue(UnsafeUtility.SizeOf <float>() == UnsafeUtility.SizeOf <int>());
            m_Index = (int *)UnsafeUtility.Malloc(4, ALIGN, allocator);
            long table_size = capacity * UnsafeUtility.SizeOf <Table>();

            m_Table = (Table *)UnsafeUtility.Malloc(table_size, ALIGN, allocator);
            long size = capacity * GetUnitSize();

            m_Data           = (byte *)UnsafeUtility.Malloc(size, ALIGN, allocator);
            m_AllocatorLabel = allocator;
            m_Capacity       = capacity;

            *m_Index = -1;
            UnsafeUtility.MemClear(m_Table, table_size);
            UnsafeUtility.MemClear(m_Data, size);
        }