C++ cli GCHandles数组

C++ cli GCHandles数组,c++-cli,C++ Cli,我在c++/cli中有一个字节数组: array<array<System::Byte>^>^ data; array^数据; 我需要将它转换为指针的C++样式向量< /p> vector<uint8_t*> cData; vectorcata; 然后,我将向函数发送cData,并在完成后释放固定内存 代码如下所示: void ProcessImages(const std::vector<const uint8_t*> srcImages

我在c++/cli中有一个字节数组:

array<array<System::Byte>^>^ data;
array^数据;
我需要将它转换为指针的C++样式向量< /p>
vector<uint8_t*> cData;
vectorcata;
然后,我将向函数发送cData,并在完成后释放固定内存

代码如下所示:

void ProcessImages(const std::vector<const uint8_t*> srcImages);

void MyCLIFunc(array<array<System::Byte>^>^ data)
{
     vector<uint8_t*> cData;

     //Does not compile
     std::vector<pin_ptr<Byte>> pinnedVector; // error C3239: 'cli::pin_ptr<unsigned char> *': pointer to interior/pin pointer is disallowed by the common language runtime`

     //Does not compile
     std::vector<GCHandle> gchandles; //>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\vector(935): error C3699: '&&': cannot use this indirection on type '_Ty' with   [ _Ty=System::Runtime::InteropServices::GCHandle  ]

     //Here I want to call ProcessImages, converting data to srcImages without copying mem
     ProcessImages(cData);
}
void ProcessImages(const std::vector srcmimages);
void MyCLIFunc(数组^data)
{
向量cData;
//不编译
std::vector pinnedVector;//错误C3239:'cli::pin_ptr*':公共语言运行库不允许指向内部的指针/pin指针`
//不编译
std::vector gchandles;/>c:\program files(x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\vector(935):错误C3699:“&&&”:无法在类型“\Ty”上与[\u Ty=System::Runtime::InteropServices::GCHandle]一起使用此间接寻址
//这里我想调用ProcessImages,将数据转换为srcImages而不复制mem
ProcessImages(cData);
}
我遗漏了什么,如何存储GCHandles/pin_ptr集合

谢谢

如果有人感兴趣: 我遇到的问题实际上是锯齿阵列的固定

我需要使用CLI数组来存储句柄, 以下代码适用于我:

auto handles = gcnew cli::array<GCHandle>(dataSize);
for (UInt32 i = 0; i < dataSize; i++)
    {
        GCHandle handle = GCHandle::Alloc(frame[i], GCHandleType::Pinned);
        handles[i] = handle;
        cData.push_back((const uint8_t*)handle.AddrOfPinnedObject().ToPointer());
    }
ProcessImages(cData);
for (UInt32 i = 0; i < dataSize; i++)
    handles[i].Free();
auto handles=gcnew cli::array(dataSize);
对于(UInt32 i=0;i<代码>不是C++,它是C++符号。C#中的字节数组看起来像
byte[][]
@Flydog57你是对的,我修改了措辞和标记这不是一个合理的问题,没有任何方法通过固定来模拟std::vector。它需要一个转换,通常是通过pin_ptr完成的,因此您可以使用std::begin/end()调用构造函数。显示您的代码。@HansPassant添加了一些示例代码,希望我的意图现在更清楚