[Test] // a stress test of sorts public void can_handle_large_allocation_spaces() { var mem = new OffsetMemorySimulator(Mega.Bytes(1), Giga.Bytes(1)); // only need enough room for arena tables var subject = new Allocator(Giga.Bytes(1), Giga.Bytes(2), mem); // big for an embedded system. 3GB total. var result = subject.Alloc(Allocator.ArenaSize / 2); Assert.That(result.Value - Giga.Bytes(1), Is.EqualTo(131072)); // allocated at bottom of given space, excluding arena tables for (int i = 0; i < 1000; i++) { result = subject.Alloc(Allocator.ArenaSize - 1); } Assert.That(subject.CurrentArena(), Is.GreaterThanOrEqualTo(1000)); Assert.That(result.Value, Is.GreaterThan(Giga.Bytes(1))); }
public const int TestSize = 10_000_000; // large enough to keep the program running for a while static void Main(string[] args) { var RamSize = Giga.Bytes(1); var rnd = new Random(); var mem = new MemorySimulator(RamSize); var subject = new TaggedHashMap(TestSize, new Allocator(0, RamSize, mem), mem); Console.WriteLine("running..."); subject.Add(0, 1); for (int i = 0; i < TestSize; i++) // 100'000 should have an acceptable run time. 25'000 should be well under a second { if (!subject.Put((ulong)rnd.Next(1, 1000000), (ulong)i, true)) { throw new Exception("Bad push"); } subject.Remove((ulong)rnd.Next(1, 1000000)); } Console.WriteLine("done"); }