/// <summary> /// Sets a range of data to a specified position into the buffer. /// </summary> /// <param name="positionInBytes">Relative position in bytes from the beginning of the buffer to set the data to.</param> /// <param name = "source">A pointer to the location to start copying from.</param> /// <param name = "count">The number of bytes to copy from source to the current buffer.</param> public void Set(int positionInBytes, IntPtr source, long count) { unsafe { SdxUtilities.CopyMemory((IntPtr)(_buffer + positionInBytes), source, (int)count); } }
/// <summary> /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. /// </summary> /// <param name="buffer">An array of bytes. This method copies <paramref name="count" /> bytes from <paramref name="buffer" /> to the current stream.</param> /// <param name="offset">The zero-based byte offset in <paramref name="buffer" /> at which to begin copying bytes to the current stream.</param> /// <param name="count">The number of bytes to be written to the current stream.</param> public void Write(IntPtr buffer, int offset, int count) { unsafe { SdxUtilities.CopyMemory((IntPtr)(_buffer + _position), new IntPtr((byte *)buffer + offset), count); _position += count; } }
internal unsafe DataBuffer(void *buffer, int sizeInBytes, bool makeCopy) { Debug.Assert(sizeInBytes > 0); if (makeCopy) { _buffer = (sbyte *)SdxUtilities.AllocateMemory(sizeInBytes); SdxUtilities.CopyMemory((IntPtr)_buffer, (IntPtr)buffer, sizeInBytes); } else { _buffer = (sbyte *)buffer; } _size = sizeInBytes; _ownsBuffer = makeCopy; }
internal unsafe DataStream(void *buffer, int sizeInBytes, bool canRead, bool canWrite, bool makeCopy) { Debug.Assert(sizeInBytes > 0); if (makeCopy) { _buffer = (byte *)SdxUtilities.AllocateMemory(sizeInBytes); SdxUtilities.CopyMemory((IntPtr)_buffer, (IntPtr)buffer, sizeInBytes); } else { _buffer = (byte *)buffer; } _size = sizeInBytes; _canRead = canRead; _canWrite = canWrite; _ownsBuffer = makeCopy; }
/// <summary> /// Writes a range of bytes 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> /// <param name = "source">A pointer to the location to start copying from.</param> /// <param name = "count">The number of bytes to copy from source to the current stream.</param> /// <exception cref = "T:System.NotSupportedException">This stream does not support writing.</exception> public void WriteRange(IntPtr source, long count) { unsafe { if (!_canWrite) { throw new NotSupportedException(); } Debug.Assert(_canWrite); Debug.Assert(source != IntPtr.Zero); Debug.Assert(count > 0); Debug.Assert((_position + count) <= _size); // TODO: use Interop.memcpy SdxUtilities.CopyMemory((IntPtr)(_buffer + _position), source, (int)count); _position += count; } }