public void TestDataBufferCopy() { long length = 400000L; DataBuffer <double> rootBuffer = new DataBuffer <double>(length); DataBuffer <double> childBufferL2 = new DataBuffer <double>(rootBuffer, 100L, length - 200L); IDataBuffer <double> childBufferL2Copy = childBufferL2.ShallowCopy(); Assert.AreSame(childBufferL2.Data, childBufferL2Copy.Data); Assert.AreSame(childBufferL2.GetUnderlyingBuffer(), childBufferL2Copy.GetUnderlyingBuffer()); Assert.AreSame(childBufferL2.GetUnderlyingRootBuffer(), childBufferL2Copy.GetUnderlyingRootBuffer()); Assert.AreEqual(childBufferL2.Length, childBufferL2Copy.Length); Assert.AreEqual(childBufferL2.Offset, childBufferL2Copy.Offset); Assert.AreEqual(childBufferL2.RelativeOffset, childBufferL2Copy.RelativeOffset); }
/// <summary> /// Create a data buffer of a certain type with a certain underlying buffer. /// </summary> /// <param name="underlyingBuffer">The underlying buffer.</param> /// <param name="offset">The offset relative to the underlying buffer.</param> /// <param name="length">The length this buffer should have.</param> public DataBuffer(IDataBuffer <T> underlyingBuffer, long offset, long length) { if (underlyingBuffer == null) { throw new ArgumentNullException(nameof(underlyingBuffer)); } CheckBufferBounds(offset, length, offset + length, underlyingBuffer.Length); Length = length; RelativeOffset = offset; Offset = offset + underlyingBuffer.Offset; _data = underlyingBuffer.Data; Type = underlyingBuffer.Type; _underlyingBuffer = underlyingBuffer; _underlyingRootBuffer = underlyingBuffer.GetUnderlyingRootBuffer() == null ? underlyingBuffer : underlyingBuffer.GetUnderlyingRootBuffer(); }