當前位置: 首頁>>代碼示例>>C#>>正文


C# IBuffer.GetPointerAtOffset方法代碼示例

本文整理匯總了C#中Windows.Storage.Streams.IBuffer.GetPointerAtOffset方法的典型用法代碼示例。如果您正苦於以下問題:C# IBuffer.GetPointerAtOffset方法的具體用法?C# IBuffer.GetPointerAtOffset怎麽用?C# IBuffer.GetPointerAtOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Storage.Streams.IBuffer的用法示例。


在下文中一共展示了IBuffer.GetPointerAtOffset方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CopyTo

        public static void CopyTo(this IBuffer source, UInt32 sourceIndex, IBuffer destination, UInt32 destinationIndex, UInt32 count)
        {
            if (source == null) throw new ArgumentNullException(nameof(source));
            if (destination == null) throw new ArgumentNullException(nameof(destination));
            if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
            if (sourceIndex < 0) throw new ArgumentOutOfRangeException(nameof(sourceIndex));
            if (destinationIndex < 0) throw new ArgumentOutOfRangeException(nameof(destinationIndex));
            if (source.Capacity <= sourceIndex) throw new ArgumentException(SR.Argument_BufferIndexExceedsCapacity);
            if (source.Capacity - sourceIndex < count) throw new ArgumentException(SR.Argument_InsufficientSpaceInSourceBuffer);
            if (destination.Capacity <= destinationIndex) throw new ArgumentException(SR.Argument_BufferIndexExceedsCapacity);
            if (destination.Capacity - destinationIndex < count) throw new ArgumentException(SR.Argument_InsufficientSpaceInTargetBuffer);
            Contract.EndContractBlock();

            // If source are destination are backed by managed arrays, use the arrays instead of the pointers as it does not require pinning:
            Byte[] srcDataArr, destDataArr;
            Int32 srcDataOffs, destDataOffs;

            bool srcIsManaged = source.TryGetUnderlyingData(out srcDataArr, out srcDataOffs);
            bool destIsManaged = destination.TryGetUnderlyingData(out destDataArr, out destDataOffs);

            if (srcIsManaged && destIsManaged)
            {
                Debug.Assert(count <= Int32.MaxValue);
                Debug.Assert(sourceIndex <= Int32.MaxValue);
                Debug.Assert(destinationIndex <= Int32.MaxValue);

                Buffer.BlockCopy(srcDataArr, srcDataOffs + (Int32)sourceIndex, destDataArr, destDataOffs + (Int32)destinationIndex, (Int32)count);
                return;
            }

            IntPtr srcPtr, destPtr;

            if (srcIsManaged)
            {
                Debug.Assert(count <= Int32.MaxValue);
                Debug.Assert(sourceIndex <= Int32.MaxValue);

                destPtr = destination.GetPointerAtOffset(destinationIndex);
                Marshal.Copy(srcDataArr, srcDataOffs + (Int32)sourceIndex, destPtr, (Int32)count);
                return;
            }

            if (destIsManaged)
            {
                Debug.Assert(count <= Int32.MaxValue);
                Debug.Assert(destinationIndex <= Int32.MaxValue);

                srcPtr = source.GetPointerAtOffset(sourceIndex);
                Marshal.Copy(srcPtr, destDataArr, destDataOffs + (Int32)destinationIndex, (Int32)count);
                return;
            }

            srcPtr = source.GetPointerAtOffset(sourceIndex);
            destPtr = destination.GetPointerAtOffset(destinationIndex);
            MemCopy(srcPtr, destPtr, count);
        }
開發者ID:dotnet,項目名稱:corefx,代碼行數:56,代碼來源:WindowsRuntimeBufferExtensions.cs


注:本文中的Windows.Storage.Streams.IBuffer.GetPointerAtOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。