do not want to copy memory buffer, but use CPTA_uchar

Hereunder a task that generates an OpenCV Mat.

I do it by loading the content of the buffer pointed at by CPTA_uchar in a string called buffer.
Then I cast it to void *.

This is an extra copy action that is not necessary. After all, the original buffer is already given by CPTA_uchar (constant pointer to array of unsigned char). But, I tried it in different ways, was not able to cast the CPTA_uchar to a (void *).

How can I use the pointer to the texture in the construction of the Mat-variable (CV::Mat), without having to copy the content ?

AsyncTask::DoneStatus example_task(GenericAsyncTask* task, void* data){
	WindowFramework *window = (WindowFramework *) data;
	PT(DisplayRegion) displayRegion = window->get_display_region_3d();
	int width = displayRegion->get_pixel_width();
	int height = displayRegion->get_pixel_height();

	PT(Texture) tex = displayRegion->get_screenshot();
	CPTA_uchar ding = tex->get_ram_image_as("BGR");
	string buffer = ding.get_data();
	void * c =  (void *) &buffer[0];
	//	void * ptr = (void *) (&ding);
	//void * ptr3 = (void *) ding;
	Mat cv_frame = Mat(cv::Size(width, height), CV_8UC3, c);
	imshow("CV window", cv_frame);

    return AsyncTask::DS_done;

get_ram_image_as(“BGR”) is an unnecessary copy operation. If the texture data is 3-channel, it is already in BGR and you can just use get_ram_image().

You can get a pointer to the data stored by the CPTA_uchar using the p() method; this avoids the extra copy step of the get_data() method.
As long as you keep a reference to the CPTA_uchar (if you cast it to a regular pointer, you’ll have to use .ref() and .unref()) the data is guaranteed to remain in memory so you don’t really need to copy it.