-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Buffers; | ||
using System.Buffers.Current; | ||
|
||
namespace MemoryLookupBenchmark | ||
{ | ||
public unsafe sealed class PointerOwnedMemory<T> : OwnedMemory<T> | ||
{ | ||
private readonly byte* _pointer; | ||
private readonly long _offset; | ||
private readonly int _length; | ||
|
||
public unsafe PointerOwnedMemory(byte* pointer, long offset, int length) | ||
{ | ||
_pointer = pointer; | ||
_offset = offset; | ||
_length = length; | ||
} | ||
|
||
public override int Length => _length; | ||
|
||
protected override void Dispose(bool disposing) { } | ||
|
||
public override bool IsDisposed => false; | ||
protected override bool IsRetained => true; | ||
|
||
public override unsafe Span<T> Span => new Span<T>(_pointer + _offset, _length); | ||
|
||
public override void Retain() | ||
{ | ||
} | ||
|
||
public override bool Release() | ||
{ | ||
return false; | ||
} | ||
|
||
public override unsafe MemoryHandle Pin(int byteOffset = 0) => new MemoryHandle(this, _pointer + _offset); | ||
|
||
protected override bool TryGetArray(out ArraySegment<T> arraySegment) | ||
{ | ||
arraySegment = null; | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters