Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Common/src/CoreLib/System/Buffers/OwnedMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Memory<T> Memory
/// <summary>
/// Returns a handle for the array that has been pinned and hence its address can be taken
/// </summary>
public abstract MemoryHandle Pin(int offset = 0);
public abstract MemoryHandle Pin(int byteOffset = 0);

/// <summary>
/// Returns an array segment.
Expand Down
6 changes: 3 additions & 3 deletions src/Common/tests/System/Buffers/NativeOwnedMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ protected override bool IsRetained

public override unsafe Span<byte> Span => new Span<byte>((void*)_ptr, _length);

public override unsafe MemoryHandle Pin(int offset = 0)
public override unsafe MemoryHandle Pin(int byteOffset = 0)
{
if (offset < 0 || offset > _length) throw new ArgumentOutOfRangeException(nameof(offset));
void* pointer = (void*)((byte*)_ptr + offset);
if (byteOffset < 0 || byteOffset > _length) throw new ArgumentOutOfRangeException(nameof(byteOffset));
void* pointer = (void*)((byte*)_ptr + byteOffset);
return new MemoryHandle(this, pointer);
}

Expand Down
2 changes: 1 addition & 1 deletion src/System.Memory/ref/System.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected OwnedMemory() { }
public abstract System.Span<T> Span { get; }
public void Dispose() { }
protected abstract void Dispose(bool disposing);
public abstract System.Buffers.MemoryHandle Pin(int offset=0);
public abstract System.Buffers.MemoryHandle Pin(int byteOffset=0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Extra space around = ?

Copy link
Author

@ahsonkhan ahsonkhan Jan 22, 2018

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public abstract bool Release();
public abstract void Retain();
protected internal abstract bool TryGetArray(out System.ArraySegment<T> arraySegment);
Expand Down
6 changes: 3 additions & 3 deletions src/System.Memory/tests/Memory/CustomMemoryForTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public override Span<T> Span
}
}

public override MemoryHandle Pin(int offset = 0)
public override MemoryHandle Pin(int byteOffset = 0)
{
unsafe
{
Retain();
if (offset < 0 || offset > _array.Length) throw new ArgumentOutOfRangeException(nameof(offset));
if (byteOffset < 0 || (byteOffset/Unsafe.SizeOf<T>()) > _array.Length) throw new ArgumentOutOfRangeException(nameof(byteOffset));
var handle = GCHandle.Alloc(_array, GCHandleType.Pinned);
return new MemoryHandle(this, Unsafe.Add<byte>((void*)handle.AddrOfPinnedObject(), offset), handle);
return new MemoryHandle(this, Unsafe.Add<byte>((void*)handle.AddrOfPinnedObject(), byteOffset), handle);
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/System.Memory/tests/Memory/Retain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ public static void MemoryFromEmptyArrayRetainWithPinning()
Memory<int> memory = new int[0];
MemoryHandle handle = memory.Retain(pin: true);
Assert.True(handle.HasPointer);
unsafe
{
int* pointer = (int*)handle.Pointer;

GC.Collect();

Assert.True(pointer != null);
}
handle.Dispose();
}

Expand Down
8 changes: 0 additions & 8 deletions src/System.Memory/tests/ReadOnlyMemory/Retain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ public static void MemoryFromEmptyArrayRetainWithPinning()
ReadOnlyMemory<int> memory = new int[0];
MemoryHandle handle = memory.Retain(pin: true);
Assert.True(handle.HasPointer);
unsafe
{
int* pointer = (int*)handle.Pointer;

GC.Collect();

Assert.True(pointer != null);
}
handle.Dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion src/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3728,7 +3728,7 @@ protected OwnedMemory() { }
public abstract System.Span<T> Span { get; }
public void Dispose() { }
protected abstract void Dispose(bool disposing);
public abstract MemoryHandle Pin(int offset=0);
public abstract MemoryHandle Pin(int byteOffset=0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

public abstract bool Release();
public abstract void Retain();
protected internal abstract bool TryGetArray(out System.ArraySegment<T> arraySegment);
Expand Down