From ee7a6272742ce9b50e5b3f0dfc2f2623f36e9057 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 11 Mar 2023 00:57:31 -0500 Subject: Data buffer patch --- lib/Net.Http/src/Helpers/InitDataBuffer.cs | 4 ++-- lib/Utils/src/Memory/Diagnostics/HeapStatistics.cs | 26 ++-------------------- 2 files changed, 4 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/Net.Http/src/Helpers/InitDataBuffer.cs b/lib/Net.Http/src/Helpers/InitDataBuffer.cs index 36e1f11..8dab633 100644 --- a/lib/Net.Http/src/Helpers/InitDataBuffer.cs +++ b/lib/Net.Http/src/Helpers/InitDataBuffer.cs @@ -60,7 +60,7 @@ namespace VNLib.Net.Http.Core /// The newly allocated data buffer internal static InitDataBuffer AllocBuffer(ArrayPool pool, int dataSize) { - //Alloc buffer + //Alloc buffer, must be zeroed byte[] buffer = pool.Rent(dataSize + POSITION_SEG_SIZE, true); return new(pool, buffer, dataSize); @@ -111,7 +111,7 @@ namespace VNLib.Net.Http.Core //Calc how many bytes can be read into the output buffer int bytesToRead = Math.Min(Remaining, buffer.Length); - Span btr = DataSegment[Position..bytesToRead]; + Span btr = DataSegment.Slice(Position, bytesToRead); //Write data to output buffer btr.CopyTo(buffer); diff --git a/lib/Utils/src/Memory/Diagnostics/HeapStatistics.cs b/lib/Utils/src/Memory/Diagnostics/HeapStatistics.cs index ec9fe0c..5d7d3f1 100644 --- a/lib/Utils/src/Memory/Diagnostics/HeapStatistics.cs +++ b/lib/Utils/src/Memory/Diagnostics/HeapStatistics.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Utils @@ -22,15 +22,13 @@ * along with VNLib.Utils. If not, see http://www.gnu.org/licenses/. */ -using System; - namespace VNLib.Utils.Memory.Diagnostics { /// /// A structures that represents the current/last captures /// statistics of the monitored heap /// - public readonly struct HeapStatistics : IEquatable + public readonly record struct HeapStatistics { /// /// The current size (in bytes) of the heap @@ -52,25 +50,5 @@ namespace VNLib.Utils.Memory.Diagnostics /// The number of allocated handles/blocks /// public readonly ulong AllocatedBlocks { get; init; } - - /// - public override bool Equals(object? obj) => obj is HeapStatistics s && Equals(s); - - /// - public override int GetHashCode() => (int)((AllocatedBytes ^ MaxBlockSize) & int.MaxValue); - - /// - public static bool operator ==(HeapStatistics left, HeapStatistics right) => left.Equals(right); - /// - public static bool operator !=(HeapStatistics left, HeapStatistics right) => !(left == right); - - /// - public bool Equals(HeapStatistics other) - { - return MinBlockSize == other.MinBlockSize - && MaxBlockSize == other.MaxBlockSize - && MaxHeapSize == other.MaxHeapSize - && AllocatedBytes == other.AllocatedBytes; - } } } -- cgit