diff --git a/Common/Util/Serialization/Compressed/CompressedVDataReader.cs b/Common/Util/Serialization/Compressed/CompressedVDataReader.cs index a18b2c1..86f9254 100644 --- a/Common/Util/Serialization/Compressed/CompressedVDataReader.cs +++ b/Common/Util/Serialization/Compressed/CompressedVDataReader.cs @@ -1,3 +1,4 @@ +using System.Buffers; using ZstdSharp; namespace Common.Util.Serialization.Compressed; @@ -9,7 +10,11 @@ public override void LoadData(Span data) { using var decompressor = new Decompressor(); var expectedSize = Decompressor.GetDecompressedSize(data); + var rented = ArrayPool.Shared.Rent((int)expectedSize); - base.LoadData(decompressor.Unwrap(data)); //TODO - Allocation here... + decompressor.Unwrap(data, rented.AsSpan()); + base.LoadData(rented); + + ArrayPool.Shared.Return(rented); } } diff --git a/Common/Util/Serialization/VDataReader.cs b/Common/Util/Serialization/VDataReader.cs index 880ec89..5bf3f39 100644 --- a/Common/Util/Serialization/VDataReader.cs +++ b/Common/Util/Serialization/VDataReader.cs @@ -25,7 +25,7 @@ public VDataReader(byte[]? data = null) { dataBuffer = data ?? new byte[256]; } - private void EnsureSize(int size) { + protected void EnsureSize(int size) { //TODO - replace with single CNPOT instead of while loop. while (dataBuffer.Length < size) { var oldBytes = dataBuffer;