From cc72ff6bfb681717726a81e2b820a823be8e614f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastiano=20Mandal=C3=A0?= Date: Sun, 10 Oct 2021 14:51:43 +0100 Subject: [PATCH] Update UnsafeBlob.cs --- .../DataStructures/Unmanaged/UnsafeBlob.cs | 65 +------------------ 1 file changed, 3 insertions(+), 62 deletions(-) diff --git a/com.sebaslab.svelto.ecs/DataStructures/Unmanaged/UnsafeBlob.cs b/com.sebaslab.svelto.ecs/DataStructures/Unmanaged/UnsafeBlob.cs index 0342839..3acd50b 100644 --- a/com.sebaslab.svelto.ecs/DataStructures/Unmanaged/UnsafeBlob.cs +++ b/com.sebaslab.svelto.ecs/DataStructures/Unmanaged/UnsafeBlob.cs @@ -177,75 +177,16 @@ namespace Svelto.ECS.DataStructures } } -// /// -// /// Note when a realloc happens it doesn't just unwrap the data, but also reset the readIndex to 0 so -// /// if readIndex is greater than 0 the index of elements of an unwrapped queue will be shifted back -// /// -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// internal void ReallocOld(uint newCapacity) -// { -// unsafe -// { -// //be sure it's multiple of 4. Assuming that what we write is aligned to 4, then we will always have aligned wrapped heads -// //the reading and writing head always increment in multiple of 4 -// newCapacity += MemoryUtilities.Pad4(newCapacity); -// -// byte* newPointer = null; -// #if DEBUG && !PROFILE_SVELTO -// if (newCapacity <= capacity) -// throw new Exception("new capacity must be bigger than current"); -// #endif -// newPointer = (byte*) MemoryUtilities.Alloc(newCapacity, allocator); -// -// //copy wrapped content if there is any -// var currentSize = _writeIndex - _readIndex; -// if (currentSize > 0) -// { -// var readerHead = _readIndex % capacity; -// var writerHead = _writeIndex % capacity; -// -// //there was no wrapping -// if (readerHead < writerHead) -// { -// //copy to the new pointer, starting from the first byte still to be read, so that readIndex -// //position can be reset -// Unsafe.CopyBlock(newPointer, ptr + readerHead, (uint) currentSize); -// } -// //the goal of the following code is to unwrap the queue into a linear array. -// //the assumption is that if the wrapped writeHead is smaller than the wrapped readHead -// //the writerHead wrapped and restart from the being of the array. -// //so I have to copy the data from readerHead to the end of the array and then -// //from the start of the array to writerHead (which is the same position of readerHead) -// else -// { -// var byteCountToEnd = capacity - readerHead; -// -// Unsafe.CopyBlock(newPointer, ptr + readerHead, byteCountToEnd); -// Unsafe.CopyBlock(newPointer + byteCountToEnd, ptr, (uint) writerHead); -// } -// } -// -// if (ptr != null) -// MemoryUtilities.Free((IntPtr) ptr, allocator); -// -// ptr = newPointer; -// capacity = newCapacity; -// -// _readIndex = 0; -// _writeIndex = currentSize; -// } -// } - /// - /// This version of Realloc unwrap a queue, but doesn't change the unwrapped index of existing elements. - /// In this way the previously index will remain valid + /// This version of Realloc unwraps a queue, but doesn't change the unwrapped index of existing elements. + /// In this way the previously indices will remain valid /// [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void Realloc(uint newCapacity) { unsafe { - //be sure it's multiple of 4. Assuming that what we write is aligned to 4, then we will always have aligned wrapped heads + //be sure it's multiple of 4. Assuming that what we write is aligned to 4, then we will always have aligned wrapped heads. //the reading and writing head always increment in multiple of 4 newCapacity += MemoryUtilities.Pad4(newCapacity);