Exemple #1
0
        public static ReadOnlySpan <T> DangerousCreate(object obj, ref T objectData, int length)
        {
            Pinnable <T> pinnable   = Unsafe.As <Pinnable <T> >(obj);
            IntPtr       byteOffset = Unsafe.ByteOffset <T>(ref pinnable.Data, ref objectData);

            return(new ReadOnlySpan <T>(pinnable, byteOffset, length));
        }
Exemple #2
0
        internal ReadOnlySpan(Pinnable <T> pinnable, IntPtr byteOffset, int length)
        {
            Debug.Assert(length >= 0);

            _length     = length;
            _pinnable   = pinnable;
            _byteOffset = byteOffset;
        }
Exemple #3
0
        public static Span <T> DangerousCreate(object obj, ref T objectData, int length)
        {
            if (obj == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj);
            }
            if (length < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
            }

            Pinnable <T> pinnable   = Unsafe.As <Pinnable <T> >(obj);
            IntPtr       byteOffset = Unsafe.ByteOffset <T>(ref pinnable.Data, ref objectData);

            return(new Span <T>(pinnable, byteOffset, length));
        }