public void poolchunk_bytealign() { var chunk = new PoolChunk(); int aligned1 = chunk.Align(6); int aligned2 = chunk.Align(20); Assert.AreEqual(aligned1, 16); Assert.AreEqual(aligned2, 32); }
public void Init() { elemSize = 16; size = 6; pageSize = 8192; maxorder = 11; capacity = (1 << maxorder) * 8192; chunk = new PoolChunk(pageSize, null); Assert.AreEqual(chunk.Capacity, capacity); Assert.AreEqual(chunk.Availables, capacity); Assert.AreEqual(chunk.Usedables, 0); }
public void poolpageList_deletefirst_mul() { var chunk = new PoolChunk(); var pagelist = new PoolPageList(8192); Assert.AreEqual(pagelist.Head, null); Assert.AreEqual(pagelist.Tail, null); int s = 0; var pages = new List <PoolPage>(); for (int i = 0; chunk.CanAlloc; i++) { s = (i + 1) * 16; if (s > 8192) { s = 8192; } var page = chunk.AllocPage(s, s); pages.Add(page); pagelist.AddLast(page); } for (int i = 0; i < pages.Count; i++) { var page1 = pagelist[i]; var page2 = pages[i]; Assert.AreEqual(page1, page2); } Assert.AreEqual(pages.Count, pagelist.Count); Console.WriteLine(pagelist.Count); try { var page2049 = pagelist[pages.Count]; Assert.Fail(); } catch (IndexOutOfRangeException) { Assert.IsTrue(true); } }
public void chunklist_move() { var chunk1 = new PoolChunk(); var chunk2 = new PoolChunk(); var chunklist1 = new PoolChunkList(0, 25); var chunklist2 = new PoolChunkList(25, 50); PoolChunkList.Link(chunklist1, chunklist2); chunklist1.AddLast(chunk1); for (int i = 0; chunk1.CanAlloc; i++) { var buf = new FixedLengthByteBuf(); PoolPage page; int s = 16 * (i + 1); if (s >= 8192) { s = 8192; } chunklist1.TryAllocPage(buf, s, s, out page); if (page == null) { Assert.Fail(); } if (chunk1.UsedPercent < 0.25) { Assert.AreNotEqual(chunklist1.Head, null); Assert.AreEqual(chunklist2.Head, null); } else { Assert.AreEqual(chunklist1.Head, null); Assert.AreNotEqual(chunklist2.Head, null); break; } } }
public void poolarena_alloc_all() { var chunk = new PoolChunk(); var arena = new PoolArena(1); IByteBuf buf = null; int allocBytes = 0; do { buf = arena.Alloc(8192); if (buf.Handle != 0) { allocBytes += 8192; Assert.AreEqual(allocBytes, arena.Useables()); } } while (buf != null && buf.Handle != 0); Assert.AreEqual(allocBytes, chunk.Capacity); }
public void poolpagelist_() { var chunk = new PoolChunk(); var pageList = new PoolPageList(16); var page1 = chunk.AllocPage(8192, 8192); var page2 = chunk.AllocPage(8192, 8192); pageList.AddLast(page1); pageList.AddLast(page2); //获得下一个可用的PoolPage var _page1 = pageList.GetNextAvailPage(); Assert.AreEqual(page1, _page1); _page1.Alloc(8192); var _page2 = pageList.GetNextAvailPage(); Assert.AreEqual(page2, _page2); }
public void chunklist_next() { var chunklist = new PoolChunkList(0, 100); var chunk1 = new PoolChunk(); var chunk2 = new PoolChunk(); chunklist.AddLast(chunk1); chunklist.AddLast(chunk2); int s = 0; for (int i = 0; chunk1.CanAlloc; i++) { s = 16 * (i + 1); if (s >= 8192) { s = 8192; } PoolPage page; var buf = new FixedLengthByteBuf(); if (!chunklist.TryAllocPage(buf, s, s, out page)) { Assert.Fail(); } Assert.AreEqual(page.Chunk, chunk1); } PoolPage page1; var buf1 = new FixedLengthByteBuf(); if (!chunklist.TryAllocPage(buf1, s, s, out page1)) { Assert.Fail(); } Assert.AreEqual(page1.Chunk, chunk2); }
public void poolpageList_deletefirst() { var chunk = new PoolChunk(); var pagelist = new PoolPageList(8192); Assert.AreEqual(pagelist.Head, null); Assert.AreEqual(pagelist.Tail, null); Assert.AreEqual(pagelist.Count, 0); var page1 = chunk.AllocPage(8192, 8192); var page2 = chunk.AllocPage(8192, 8192); pagelist.AddLast(page1); Assert.AreEqual(pagelist.Count, 1); Assert.AreEqual(pagelist.Head, page1); Assert.AreEqual(pagelist.Tail, page1); pagelist.DeleteFirst(); Assert.AreEqual(pagelist.Count, 0); Assert.AreEqual(pagelist.Head, null); Assert.AreEqual(pagelist.Tail, null); pagelist.AddLast(page1); Assert.AreEqual(pagelist.Count, 1); Assert.AreEqual(pagelist.Head, page1); Assert.AreEqual(pagelist.Tail, page1); pagelist.AddLast(page2); Assert.AreEqual(pagelist.Count, 2); Assert.AreEqual(pagelist.Head, page1); Assert.AreEqual(pagelist.Tail, page2); pagelist.DeleteFirst(); Assert.AreEqual(pagelist.Count, 1); Assert.AreEqual(pagelist.Head, page2); Assert.AreEqual(pagelist.Tail, page2); }