Exemplo n.º 1
0
        // Writes the struct pointed to by ref value into unmanaged memory.  Note that this method
        // is most performant when used with medium to large sized structs (larger than 8 bytes
        // though this is number is JIT and architecture dependent).   As such, it is best to use
        // the WriteX methods for small standard types such as ints, longs, bools, etc.
        public void Write <T>(long position, ref T structure) where T : struct
        {
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (!_isOpen)
            {
                throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
            }
            if (!_canWrite)
            {
                throw new NotSupportedException(SR.NotSupported_Writing);
            }

            uint sizeOfT = SafeBuffer.SizeOf <T>();

            if (position > _capacity - sizeOfT)
            {
                if (position >= _capacity)
                {
                    throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
                }
                else
                {
                    throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToWrite, typeof(T)), nameof(position));
                }
            }

            _buffer.Write <T>((ulong)(_offset + position), structure);
        }
Exemplo n.º 2
0
        [System.Security.SecurityCritical]  // auto-generated_required
        public void Write <T>(Int64 position, ref T structure) where T : struct
        {
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            Contract.EndContractBlock();

            if (!_isOpen)
            {
                throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed"));
            }
            if (!CanWrite)
            {
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_Writing"));
            }

            UInt32 sizeOfT = Marshal.SizeOfType(typeof(T));

            if (position > _capacity - sizeOfT)
            {
                if (position >= _capacity)
                {
                    throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired"));
                }
                else
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToWrite", typeof(T).FullName), "position");
                }
            }

            _buffer.Write <T>((UInt64)(_offset + position), structure);
        }
Exemplo n.º 3
0
        // Writes the struct pointed to by ref value into unmanaged memory.  Note that this method
        // is most performant when used with medium to large sized structs (larger than 8 bytes
        // though this is number is JIT and architecture dependent).   As such, it is best to use
        // the WriteX methods for small standard types such as ints, longs, bools, etc.

        public void Write <T>(Int64 position, ref T structure) where T : struct
        {
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
            }

            if (!_isOpen)
            {
                throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed);
            }
            if (!CanWrite)
            {
                throw new NotSupportedException(SR.NotSupported_Writing);
            }

            UInt32 sizeOfT = Marshal.SizeOfType(typeof(T));

            if (position > _capacity - sizeOfT)
            {
                if (position >= _capacity)
                {
                    throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
                }
                else
                {
                    throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToWrite, typeof(T).FullName), nameof(position));
                }
            }

            _buffer.Write <T>((UInt64)(_offset + position), structure);
        }
Exemplo n.º 4
0
        /// <summary>
        // Writes the struct pointed to by ref value into unmanaged memory.  Note that this method
        // is most performant when used with medium to large sized structs (larger than 8 bytes
        // though this is number is JIT and architecture dependent).   As such, it is best to use
        // the WriteX methods for small standard types such as ints, longs, bools, etc.
        /// </summary>
        public void Write <T>(Int64 position, ref T structure) where T : struct
        {
            int sizeOfType = Unsafe.SizeOf <T>();

            EnsureSafeToWrite(position, sizeOfType);

            _buffer.Write <T>((UInt64)(_offset + position), structure);
        }
Exemplo n.º 5
0
        private void NativeFlush()
        {
            NativeBinding nb;

            GetCurrentNativeBinding(out nb);

            if (!IsDirty && nb.IsValid)
            {
                return;
            }

            ScratchBuffer.Write <T>(0, _ValueContainer.Current);

            var pScratch = ScratchBuffer.DangerousGetHandle();
            var pUpload  = UploadBuffer.DangerousGetHandle();

            // Fix-up matrices because the in-memory order is transposed :|
            foreach (var fixup in nb.Fixups)
            {
                var pSource = (pScratch + fixup.FromOffset);
                var pDest   = (pUpload + fixup.ToOffset);

                if (fixup.TransposeMatrix)
                {
                    InPlaceTranspose((float *)pSource);
                }

                Buffer.MemoryCopy(
                    pSource.ToPointer(),
                    pDest.ToPointer(),
                    fixup.DataSize, fixup.DataSize
                    );
            }

            // HACK: Bypass the COM wrapper and invoke directly from the vtable.
            var hr = nb.pSetRawValue(nb.pUnboxedEffect, nb.hParameter, pUpload.ToPointer(), 0, nb.UploadSize);

            Marshal.ThrowExceptionForHR(hr);
            // pEffect.SetRawValue(hParameter, pUpload.ToPointer(), 0, UploadSize);
        }
Exemplo n.º 6
0
        public void Write(long position, bool value)
        {
            if (!canwrite)
            {
                throw new NotSupportedException();
            }
            if (buffer == null)
            {
                throw new ObjectDisposedException("buffer");
            }
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            buffer.Write((ulong)position, value);
        }