/// <summary>Ceate a new slice buffer with the specified page size</summary> /// <param name="pageSize">Initial page size</param> public SliceBuffer(int pageSize) { if (pageSize < 0) { throw new ArgumentOutOfRangeException("pageSize", "Page size cannt be less than zero"); } m_pageSize = pageSize == 0 ? DefaultPageSize : SliceHelpers.Align(pageSize); }
public void Test_SliceHelpers_Align() { // Even though 0 is a multiple of 16, it is always rounded up to 16 to simplify buffer handling logic Assert.That(SliceHelpers.Align(0), Is.EqualTo(16)); // 1..16 => 16 for (int i = 1; i <= 16; i++) { Assert.That(SliceHelpers.Align(i), Is.EqualTo(16), "Align({0}) => 16", i); } // 17..32 => 32 for (int i = 17; i <= 32; i++) { Assert.That(SliceHelpers.Align(i), Is.EqualTo(32), "Align({0}) => 32", i); } // 33..48 => 48 for (int i = 33; i <= 48; i++) { Assert.That(SliceHelpers.Align(i), Is.EqualTo(48), "Align({0}) => 48", i); } // 2^N-1 for (int i = 6; i < 30; i++) { Assert.That(SliceHelpers.Align((1 << i) - 1), Is.EqualTo(1 << i)); } // largest non overflowing Assert.That(() => SliceHelpers.Align(int.MaxValue - 15), Is.EqualTo((int.MaxValue - 15))); // overflow Assert.That(() => SliceHelpers.Align(int.MaxValue), Throws.InstanceOf <OverflowException>()); Assert.That(() => SliceHelpers.Align(int.MaxValue - 14), Throws.InstanceOf <OverflowException>()); // negative values Assert.That(() => SliceHelpers.Align(-1), Throws.InstanceOf <ArgumentOutOfRangeException>()); Assert.That(() => SliceHelpers.Align(int.MinValue), Throws.InstanceOf <ArgumentOutOfRangeException>()); }