forked from dotnet/corefxlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReservedReadOnlyMemory.cs
34 lines (30 loc) · 986 Bytes
/
ReservedReadOnlyMemory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
namespace System.Buffers
{
public struct ReservedReadOnlyMemory<T> : IDisposable
{
OwnedMemory<T> _owner;
ReadOnlyMemory<T> _memory;
long _versionId;
int _reservationId;
internal ReservedReadOnlyMemory(ref ReadOnlyMemory<T> memory, OwnedMemory<T> owner, long versionId, int reservationId)
{
_versionId = versionId;
_owner = owner;
_reservationId = _owner.AddReference(versionId, reservationId);
_memory = new ReadOnlyMemory<T>(ref memory, _reservationId);
}
public bool IsDisposed => _owner.IsDependancyDisposed(_versionId, _reservationId);
public ReadOnlyMemory<T> Memory
{
get
{
_owner.ThrowIfDisposed(_versionId, _reservationId);
return _memory;
}
}
public void Dispose()
{
_owner.Release(_versionId, _reservationId);
}
}
}