本文整理汇总了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);
}