/// <summary> /// Sets an array of values to a specified position into the buffer. /// </summary> /// <typeparam name = "T">The type of the values to be written to the buffer.</typeparam> /// <param name="positionInBytes">Relative position in bytes from the beginning of the buffer to set the data to.</param> /// <param name = "data">An array of values to be written to the buffer.</param> /// <param name = "offset">The zero-based offset in data at which to begin copying values to the current buffer.</param> /// <param name = "count">The number of values to be written to the current buffer. If this is zero, /// all of the contents <paramref name = "data" /> will be written.</param> public void Set <T>(int positionInBytes, T[] data, int offset, int count) where T : struct { unsafe { SdxUtilities.Write((IntPtr)(_buffer + positionInBytes), data, offset, count); } }
/// <summary> /// Writes an array of values to the current stream, and advances the current position /// within this stream by the number of bytes written. /// </summary> /// <remarks> /// In order to provide faster read/write, this operation doesn't check stream bound. /// A client must carefully not read/write above the size of this datastream. /// </remarks> /// <typeparam name = "T">The type of the values to be written to the stream.</typeparam> /// <param name = "data">An array of values to be written to the stream.</param> /// <param name = "offset">The zero-based offset in data at which to begin copying values to the current stream.</param> /// <param name = "count">The number of values to be written to the current stream. If this is zero, /// all of the contents <paramref name = "data" /> will be written.</param> /// <exception cref = "T:System.NotSupportedException">This stream does not support writing.</exception> public void WriteRange <T>(T[] data, int offset, int count) where T : struct { unsafe { if (!_canWrite) { throw new NotSupportedException(); } _position = (byte *)SdxUtilities.Write((IntPtr)(_buffer + _position), data, offset, count) - _buffer; } }
/// <summary> /// Writes the content of the specified buffer to the unmanaged memory location of this instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="buffer">The buffer to read from.</param> /// <param name="offset">The offset in the array to read from.</param> /// <param name="count">The number of T element to write to the memory location.</param> /// <exception cref="System.ArgumentNullException">buffer</exception> /// <exception cref="System.InvalidOperationException">DataPointer is Zero</exception> /// <exception cref="System.ArgumentOutOfRangeException">buffer;Total buffer size cannot be larger than size of this data pointer</exception> public void CopyFrom <T>(T[] buffer, int offset, int count) where T : struct { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Must be >= 0"); } if (count <= 0) { throw new ArgumentOutOfRangeException("count", "Must be > 0"); } if (count * SdxUtilities.SizeOf <T>() > Size) { throw new ArgumentOutOfRangeException("buffer", "Total buffer size cannot be larger than size of this data pointer"); } SdxUtilities.Write(Pointer, buffer, offset, count); }