c++ - 两个 C++/CX Platform::Array:s 之间的高效复制方法?

标签 c++ windows-runtime copy c++-cx

我想将 Platform::Array 对象中的一系列项目复制到另一个 Platform::Array。我当然可以解决这个问题,例如使用 for 循环:

int srcIdx = srcIdx0;
int destIdx = destIdx0;
for (int i = 0; i < count; ++i, ++srcIdx, ++destIdx)
    dest[destIdx] = src[srcIdx];

我想知道的是,C++/CX(组件扩展)中是否有一些内置功能可以更高效、更简洁地执行此操作?

在 C# 中,有 Array.Copy方法,并使用 C++/CLI Marshal.Copy至少对于复制“原始”类型来说是一个选择。

在 C++ STL 中,有 std::copystd::copy_n,但据我所知,这些算法不适用于 平台: :Array “迭代器” begin()end()

是否有一个“隐藏”在某处的 C++/CX 便捷复制方法,或者我是否必须为该操作回退到显式 for 循环?

最佳答案

此时似乎没有内置的Platform::Array 复制方法,所以我为此实现了自己的模板函数:

template<typename T> void Copy(
    const Platform::Array<T>^ sourceArray, 
    int sourceIndex, 
    Platform::Array<T>^ destinationArray, 
    int destinationIndex, 
    int length)
{
    for (int i = 0; i < length; ++i, ++sourceIndex, ++destinationIndex)
        destinationArray[destinationIndex] = sourceArray[sourceIndex];
};

非常欢迎关于如何改进复制部分的建议:-)

关于c++ - 两个 C++/CX Platform::Array:s 之间的高效复制方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14724668/

相关文章:

c# - 如何使用 XAudio2 以毫秒为单位寻找位置

c# - WinRT 图像处理

excel - VBA:打开 xls 文件并将其添加到当前工作簿

string - Delphi字符串内存泄漏?

c++ - 消除多重继承中的类成员歧义

c++ - 自上而下的伸展树(Splay Tree)的 makeEmpty() 的时间复杂度

c# - 什么可以解释通过 WinRT 在 UDP 多播中的这种行为?

c++ - while( cin >> value ) 在我输入一个字符时打破循环

c++ - 在 OpenCV 中使用指针检索深度

c++ - memcpy vs for 循环 - 从指针复制数组的正确方法是什么?