Ejemplo n.º 1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "DataBuffer" /> class, and allocates a new buffer to use as a backing store.
        /// </summary>
        /// <param name = "sizeInBytes">The size of the buffer to be allocated, in bytes.</param>
        /// <exception cref = "T:System.ArgumentOutOfRangeException">
        ///   <paramref name = "sizeInBytes" /> is less than 1.</exception>
        public DataBuffer(int sizeInBytes)
        {
            unsafe
            {
                Debug.Assert(sizeInBytes > 0);

                _buffer     = (sbyte *)SdxUtilities.AllocateMemory(sizeInBytes);
                _size       = sizeInBytes;
                _ownsBuffer = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "DataStream" /> class, and allocates a new buffer to use as a backing store.
        /// </summary>
        /// <param name = "sizeInBytes">The size of the buffer to be allocated, in bytes.</param>
        /// <param name = "canRead">
        ///   <c>true</c> if reading from the buffer should be allowed; otherwise, <c>false</c>.</param>
        /// <param name = "canWrite">
        ///   <c>true</c> if writing to the buffer should be allowed; otherwise, <c>false</c>.</param>
        public DataStream(int sizeInBytes, bool canRead, bool canWrite)
        {
            unsafe
            {
                Debug.Assert(sizeInBytes > 0);

                _buffer     = (byte *)SdxUtilities.AllocateMemory(sizeInBytes);
                _size       = sizeInBytes;
                _ownsBuffer = true;
                _canRead    = canRead;
                _canWrite   = canWrite;
            }
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 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;
 }