Introduce a unified Reallocate method to all memory allocator types (Arena, Stack, FreeList, VirtualArena, VirtualStack, DynamicArena) and require it in the IMemoryAllocator interface. This enables efficient resizing of memory blocks, with fast-path optimizations for stack-like allocators. Update AllocationManager and MemoryPool to use the new Reallocate method, simplifying and optimizing memory resizing logic. Add public properties for buffer pointers, sizes, and offsets to allocator structs for easier diagnostics. Set FreeList's default concurrency level to 1 and make its allocation method return null on dispose instead of throwing. Clean up vector types for formatting, fix UnsafeList's RemoveRangeSwapBack logic, and simplify RemoveAtSwapBack. Simplify Program.cs to only run SPMDBenchmark. Add new unit tests for FixedString, UnsafeList, UnsafeHashMap, and UnsafeHashSet. Apply minor test code cleanups for consistency in TestUnsafeQueue. BREAKING CHANGE: IMemoryAllocator now requires a Reallocate method, and allocator APIs have changed accordingly.
54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using Misaki.HighPerformance.LowLevel.Collections;
|
|
|
|
namespace Misaki.HighPerformance.Test.UnitTest.Collections;
|
|
|
|
[TestClass]
|
|
public class TestFixedString
|
|
{
|
|
[TestMethod]
|
|
public void TestFixedString32()
|
|
{
|
|
var fs = new FixedString32("Hello");
|
|
Assert.AreEqual(5, fs.Length);
|
|
Assert.AreEqual("Hello", fs.ToString());
|
|
Assert.AreEqual("Hello", fs.Value);
|
|
|
|
fs.Value = "World";
|
|
Assert.AreEqual(5, fs.Length);
|
|
Assert.AreEqual("World", fs.Value);
|
|
|
|
fs.Value = "";
|
|
Assert.AreEqual(0, fs.Length);
|
|
Assert.AreEqual("", fs.Value);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestFixedString32TooLong()
|
|
{
|
|
// MAX_LENGTH is 15
|
|
try
|
|
{
|
|
new FixedString32("This string is definitely longer than 15 characters");
|
|
Assert.Fail("Should have thrown ArgumentException");
|
|
}
|
|
catch (ArgumentException)
|
|
{
|
|
// Success
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestFixedString64()
|
|
{
|
|
var fs = new FixedString64("A bit longer string");
|
|
Assert.AreEqual("A bit longer string", fs.Value);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestFixedString128()
|
|
{
|
|
var fs = new FixedString128("Even longer string for 128 bytes buffer");
|
|
Assert.AreEqual("Even longer string for 128 bytes buffer", fs.Value);
|
|
}
|
|
}
|