Преглед изворни кода

Update UnsafeBlob.cs

pull/72/head
Sebastiano Mandalà GitHub пре 2 година
родитељ
комит
cc72ff6bfb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 измењених фајлова са 3 додато и 62 уклоњено
  1. +3
    -62
      com.sebaslab.svelto.ecs/DataStructures/Unmanaged/UnsafeBlob.cs

+ 3
- 62
com.sebaslab.svelto.ecs/DataStructures/Unmanaged/UnsafeBlob.cs Прегледај датотеку

@@ -177,75 +177,16 @@ namespace Svelto.ECS.DataStructures
}
}

// /// <summary>
// /// 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
// /// </summary>
// [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;
// }
// }
/// <summary>
/// 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
/// </summary>
[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);



Loading…
Откажи
Сачувај