From 3b7004b88acfc7f7baa3a8857a5a2f7cf3dd560e Mon Sep 17 00:00:00 2001 From: vnugent Date: Fri, 17 May 2024 16:03:28 -0400 Subject: feat: Added ReadFileDataAsync function --- lib/Utils/src/Extensions/MemoryExtensions.cs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'lib/Utils/src') diff --git a/lib/Utils/src/Extensions/MemoryExtensions.cs b/lib/Utils/src/Extensions/MemoryExtensions.cs index 083c7cf..c433527 100644 --- a/lib/Utils/src/Extensions/MemoryExtensions.cs +++ b/lib/Utils/src/Extensions/MemoryExtensions.cs @@ -146,8 +146,13 @@ namespace VNLib.Utils.Extensions /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemoryManager DirectAlloc(this IUnmangedHeap heap, nuint size, bool zero = false) where T : unmanaged + public static MemoryManager DirectAlloc(this IUnmangedHeap heap, int size, bool zero = false) where T : unmanaged { + /* + * Size it limited to int32 because the memory manager uses int32 for length + * and the constructor will attempt to cast the size to int32 or cause an + * overflow exception + */ MemoryHandle handle = heap.Alloc(size, zero); return new SysBufferMemoryManager(handle, true); } @@ -177,24 +182,6 @@ namespace VNLib.Utils.Extensions //Method only exists for consistancy since unsafe handles are always 32bit [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetIntLength(this in UnsafeMemoryHandle handle) where T : unmanaged => handle.IntLength; - - /// - /// Allows direct allocation of a fixed size from a instance - /// of the specified number of elements - /// - /// The unmanaged data type - /// - /// The number of elements to allocate on the heap - /// Optionally zeros conents of the block when allocated - /// The wrapper around the block of memory - /// - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemoryManager DirectAlloc(this IUnmangedHeap heap, nint size, bool zero = false) where T : unmanaged - { - ArgumentOutOfRangeException.ThrowIfNegative(size); - return DirectAlloc(heap, (nuint)size, zero); - } /// /// Gets an offset pointer from the base postion to the number of bytes specified. Performs bounds checks -- cgit