From 9bc852334b1d5453b45c3cfc30a09e0fc9da2d3e Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 21 Nov 2024 20:21:32 +0300 Subject: [PATCH] Experimenting with blobs --- src/vm/util/blob.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/vm/util/blob.cs b/src/vm/util/blob.cs index 0b8f662f..16e18742 100644 --- a/src/vm/util/blob.cs +++ b/src/vm/util/blob.cs @@ -1,5 +1,4 @@ using System; -using System.Buffers; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -28,6 +27,9 @@ static class PoolHolder where T1 : unmanaged }); } + internal Blob() + {} + static public Blob New(ref T val) { var pool = PoolHolder.pool.Value; @@ -37,6 +39,7 @@ static public Blob New(ref T val) { ++pool.miss; blob = new Blob(); + blob.data = new byte[Size]; } else { @@ -44,13 +47,9 @@ static public Blob New(ref T val) blob = pool.stack.Pop(); } - var data = ArrayPool.Shared.Rent(Size); - - ref var valRef = ref Unsafe.As(ref data[0]); - valRef = val; + Unsafe.As(ref blob.data[0]) = val; blob._refs = 1; - blob.data = data; blob.pool = pool; return blob; @@ -83,7 +82,6 @@ static void Del(Blob blob) throw new Exception("Freeing invalid object, refs " + blob._refs); blob._refs = -1; - ArrayPool.Shared.Return(blob.data); blob.pool.stack.Push(blob); }