Skip to content

Commit b10821b

Browse files
committed
Fixed extension receiver type
1 parent c7066b2 commit b10821b

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/DotNext.Tests/Buffers/UnmanagedMemoryPoolTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static unsafe void Pinning()
242242
public static unsafe void MarshalAsMemory()
243243
{
244244
var ptr = stackalloc int[] { 10, 20, 30 };
245-
var memory = Memory<int>.FromPointer(ptr, 3);
245+
var memory = MemoryMarshal.AsMemory(ptr, 3);
246246
False(memory.IsEmpty);
247247
Equal([10, 20, 30], memory.Span);
248248

src/DotNext.Unsafe/Buffers/UnmanagedMemory.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static UnmanagedMemoryOwner<T, TAllocator> Allocate<TAllocator>(int leng
6464
public static MemoryAllocator<T> Unmanaged => GetAllocator<T>(zeroMem: false);
6565

6666
/// <summary>
67-
/// Gets the unmanaged memoir
67+
/// Gets the unmanaged memory allocator that can be used to obtain a block of unmanaged memory filled with zeroes.
6868
/// </summary>
6969
public static MemoryAllocator<T> UnmanagedZeroMem => GetAllocator<T>(zeroMem: true);
7070

@@ -83,17 +83,18 @@ static MemoryOwner<T> Allocate<TAllocator>(int length)
8383
/// <summary>
8484
/// Extends <see cref="Memory{T}"/> type.
8585
/// </summary>
86-
/// <typeparam name="T">The type of elements in the memory.</typeparam>
87-
extension<T>(Memory<T>) where T : unmanaged
86+
extension(MemoryMarshal)
8887
{
8988
/// <summary>
9089
/// Wraps unmanaged pointer to <see cref="Memory{T}"/>.
9190
/// </summary>
91+
/// <typeparam name="T">The type of elements in the memory.</typeparam>
9292
/// <param name="pointer">The pointer to a sequence of elements.</param>
9393
/// <param name="length">The number of elements.</param>
9494
/// <returns>The memory block that represents the data located at the pointer.</returns>
9595
[CLSCompliant(false)]
96-
public static unsafe Memory<T> FromPointer(T* pointer, int length)
96+
public static unsafe Memory<T> AsMemory<T>(T* pointer, int length)
97+
where T : unmanaged
9798
{
9899
ArgumentNullException.ThrowIfNull(pointer);
99100
ArgumentOutOfRangeException.ThrowIfNegative(length);

src/DotNext.Unsafe/IO/PointerExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Runtime.InteropServices;
2+
13
namespace DotNext.IO;
24

35
using Buffers;
@@ -170,7 +172,7 @@ private static async ValueTask WriteToAsync(Pointer<byte> source, long length, S
170172
Memory<byte> memory;
171173
unsafe
172174
{
173-
memory = Memory<byte>.FromPointer(source, count);
175+
memory = MemoryMarshal.AsMemory<byte>(source, count);
174176
}
175177

176178
await destination.WriteAsync(memory, token).ConfigureAwait(false);
@@ -197,7 +199,7 @@ private static async ValueTask<long> ReadFromStreamAsync(Stream source, Pointer<
197199
Memory<byte> memory;
198200
unsafe
199201
{
200-
memory = Memory<byte>.FromPointer(destination, int.CreateSaturating(length));
202+
memory = MemoryMarshal.AsMemory<byte>(destination, int.CreateSaturating(length));
201203
}
202204

203205
if ((bytesRead = await source.ReadAsync(memory, token).ConfigureAwait(false)) is 0)

0 commit comments

Comments
 (0)