Esempio n. 1
0
        public AllocationHandle Transfer(ref AllocationHandle handle)
        {
            var copy = handle;

            handle = new AllocationHandle(IntPtr.Zero, 0, 0);
            return(copy);
        }
Esempio n. 2
0
 //TODO: Should we really clear to zero by default?
 //the EntityChunk should be managing out of bounds indexing and moving of data
 public StackAllocator(IAllocator allocator, int size, bool thrash = false)
 {
     _allocator = allocator;
     _handle    = allocator.Take(size);
     _free      = (uint)size;
     _dataPtr   = _handle.Address;
     _thrash    = thrash;
 }
        public void IterationSetup()
        {
            _handle = _memory.Take(N * sizeof(float));
            var addr = (float *)_handle.Address;

            for (var i = 0; i < N; i++)
            {
                addr[i] = 0.0001f;
            }
        }
 public void Free(ref AllocationHandle handle)
 {
     AssertValid(ref handle);
     //_logger.LogDebug($"DynamicAlloc freeing {handle}");
     Marshal.FreeHGlobal(handle.Address);
     _size -= _handles[handle.Id].Size;
     _handles[handle.Id] = new DynamicMemoryHandle(IntPtr.Zero, 0, 0, 0);
     handle = AllocationHandle.Null;
     --_blocks;
 }
Esempio n. 5
0
            public HeapPage(ILoggerFactory logFactory, IAllocator allocator, int size)
            {
                _logger    = logFactory.CreateLogger <HeapPage>();
                _allocator = allocator;
                _handle    = allocator.Take((int)size);
                Size       = size;
                _heap      = (HeapAllocation *)_handle.Address;
                *_heap = new HeapAllocation(size);

                // _enableLogging = enableLogging;
                // if (_enableLogging)
                //     _stackTrace = new string[_heap->Blocks];
            }
        internal ComponentDataArray(ILoggerFactory logFactory, IAllocator allocator, ComponentType componentType, int length)
        {
            _logFactory = logFactory;
            _logger     = _logFactory.CreateLogger <ComponentDataArray>();

            ElementSize = componentType.Size;
            Length      = length;

            _componentType   = componentType;
            _componentHelper = ComponentTypeHelper.Get(componentType);

            _allocator    = allocator;
            _memoryHandle = allocator.Take(componentType.Size * length);
        }
        public NativeArray(IAllocator allocator, int length)
        {
            Allocator = allocator;
            var sizeOfElement = SizeOf <T> .Size;

            if (length > 0)
            {
                Handle = allocator.Take <T>(length);
                Length = length;
            }
            else
            {
                Handle = default;
                Length = 0;
            }
        }
Esempio n. 8
0
        public unsafe void Free(ref AllocationHandle handle)
        {
            Contract.EqualTo(handle.Id, _allocationIndex - 1);
            _allocationIndex--;
            //Contract.Assert(handle.Id == _allocationIndex);
            //Contract.Requires(handle.Id == _allocationIndex);
            //handle.Id.AssertShouldBe(_allocationIndex);
            _dataPtr = IntPtr.Subtract(_dataPtr, (int)handle.Flags);

            if (_thrash)
            {
                Unsafe.ClearAlign16((void *)handle.Address, (int)handle.Flags, _thrashValue);
            }

            handle = AllocationHandle.Null;
        }
 private void AssertValid(ref AllocationHandle handle)
 {
     Assert.Range(handle.Id, 0, (uint)_handles.Length);
     ref var h = ref _handles[handle.Id];
 public AllocationHandle Transfer(ref AllocationHandle handle)
 {
     lock (_allocator)
         return(_allocator.Transfer(ref handle));
 }
 public void Free(ref AllocationHandle handle)
 {
     lock (_allocator)
         _allocator.Free(ref handle);
 }
Esempio n. 12
0
 public void Free(ref AllocationHandle handle)
 {
     ref var ptr = ref _allocations[handle.Id];