GCHandle 数组

Array of GCHandles

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

array<array<System::Byte>^>^ data;

我需要将其转换为指针的 C++ 样式向量

vector<uint8_t*> cData;

然后我会将 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 studio17\professional\vc\tools\msvc.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);
}

我缺少什么,如何存储 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();