This bit of code is from a device supplier for which I am utilizing their libraries. I am no programming expert by any means and need to understand this for a research project.
pin_ptr<System::Byte> pinPtrArray;
pinPtrArray = &e->GetImageData->dataRawPixels2Byte[0];
Mat im (e->Width, e->Height, CV_16U, pinPtrArray);
Does anyone understand what pin_ptr<System::Byte>
is? Furthermore, what does implementing this into a Mat container do? If someone could explain, it would be greatly appreciated.
Here you have detailed explanation of pin_ptr
. In managed world of C++/CLI (.NET Framework) objects in heap (in memory) are managed by garbage collector. It can move objects in order to prevent memory fragmentation. It can also delete object if the object is out of scope. When you are using managed memory in native environment (here Mat
is native object and e
is managed) you have to "pin" this managed object in order to prevent the object pointed to from moving on the managed heap. Now you can use data pointed by pinPtrArray
safely. Garbage collector will not move it during runtime.