public void Update(string key, TValue value) { using var s = PooledMemoryStream.New(); _serialize(value, s.MemoryStream); _table.Update(key, s.MemoryStream.ToArray()); }
public void PooledMemoryStream_GottenTooBig() { var bigPool = MemoryStreamPool.Create(1, 16, 2048); var smallPool = MemoryStreamPool.Create(1, 16, 16); TooBig(() => PooledMemoryStream.New(), h => h.MemoryStream, (h, n) => h.Write(new byte[n], 0, n), 1024); TooBig(() => bigPool.New(), h => h.MemoryStream, (h, n) => h.Write(new byte[n], 0, n), 2048); TooBig(() => smallPool.New(), h => h.MemoryStream, (h, n) => h.Write(new byte[n], 0, n), 16); }
public void PooledMemoryStream_DiscardIfNotWritable() { var i = 0; TooBig(() => PooledMemoryStream.New(), h => h.MemoryStream, (h, n) => { if (++i == 2) { h.Dispose(); } }, 16); }
public void PooledMemoryStream_GlobalPool() { for (var i = 0; i < 100; i++) { using var obj = PooledMemoryStream.New(); var ms = obj.MemoryStream; Assert.AreEqual(0, ms.Length); ms.Write(bytes, 0, 4); } }
private static void PooledMemoryStream_Simple_Impl(MemoryStreamPool pool) { for (var i = 0; i < 100; i++) { using var obj = i % 2 == 0 ? pool.New() : PooledMemoryStream.New(pool); var ms = obj.MemoryStream; Assert.AreEqual(0, ms.Length); ms.Write(bytes, 0, 4); } }