public void can_allocate_memory_from_a_pool_and_get_a_pointer() { var mem = new MemorySimulator(Mega.Bytes(1)); var subject = new Allocator(100, Mega.Bytes(10), mem); long ptr = subject.Alloc(byteCount: Kilo.Bytes(1)).Value; Assert.That(ptr, Is.GreaterThanOrEqualTo(100)); }
public void allocating_enough_memory_changes_arena() { var mem = new MemorySimulator(Mega.Bytes(1)); var subject = new Allocator(100, Mega.Bytes(1), mem); int first = subject.CurrentArena(); long ptr1 = subject.Alloc(Allocator.ArenaSize).Value; long ptr2 = subject.Alloc(Kilo.Bytes(1)).Value; int second = subject.CurrentArena(); Assert.That(ptr1, Is.Not.EqualTo(ptr2)); Assert.That(first, Is.Not.EqualTo(second)); }
public void elements_per_chunk_is_reasonable() { Console.WriteLine(Allocator.ArenaSize); var mem_a = new MemorySimulator(Kilo.Bytes(80)); var mem_b = new MemorySimulator(Kilo.Bytes(80)); var mem_c = new MemorySimulator(Kilo.Bytes(80)); var structVector = new Vector <SampleElement>(new Allocator(0, Kilo.Bytes(80), mem_a), mem_a); var bigStructVector = new Vector <HugeStruct> (new Allocator(0, Kilo.Bytes(80), mem_b), mem_b); var byteVector = new Vector <byte> (new Allocator(0, Kilo.Bytes(80), mem_c), mem_c); Assert.That(byteVector.ElemsPerChunk, Is.LessThan(70)); // Not too big on small elements Assert.That(structVector.ElemsPerChunk, Is.GreaterThan(30)); Assert.That(bigStructVector.ElemsPerChunk, Is.LessThan(32)); // scales down to fit arenas }