@@ -130,6 +130,12 @@ public void Test_MemoryOwnerOfT_AllocateAndGetArray()
130130 {
131131 var buffer = MemoryOwner < int > . Allocate ( 127 ) ;
132132
133+ // Here we allocate a MemoryOwner<T> instance with a requested size of 127, which means it
134+ // internally requests an array of size 127 from ArrayPool<T>.Shared. We then get the array
135+ // segment, so we need to verify that (since buffer is not disposed) the returned array is
136+ // not null, is of size >= the requested one (since ArrayPool<T> by definition returns an
137+ // array that is at least of the requested size), and that the offset and count properties
138+ // match our input values (same length, and offset at 0 since the buffer was not sliced).
133139 var segment = buffer . DangerousGetArray ( ) ;
134140
135141 Assert . IsNotNull ( segment . Array ) ;
@@ -139,10 +145,14 @@ public void Test_MemoryOwnerOfT_AllocateAndGetArray()
139145
140146 var second = buffer . Slice ( 10 , 80 ) ;
141147
148+ // The original buffer instance is disposed here, because calling Slice transfers
149+ // the ownership of the internal buffer to the new instance (this is documented in
150+ // XML docs for the MemoryOwner<T>.Slice method).
142151 Assert . ThrowsException < ObjectDisposedException > ( ( ) => buffer . DangerousGetArray ( ) ) ;
143152
144153 segment = second . DangerousGetArray ( ) ;
145154
155+ // Same as before, but we now also verify the initial offset != 0, as we used Slice
146156 Assert . IsNotNull ( segment . Array ) ;
147157 Assert . IsTrue ( segment . Array . Length >= second . Length ) ;
148158 Assert . AreEqual ( segment . Offset , 10 ) ;
0 commit comments