1
我目前使用這種方法來一些字節值複製過來:C++指針字節數組優化
for (int i = 0; i < (iLen + 1); i++)
{
*(pBuffer + i) = Image.pVid[i];
}
我想問一下,如果有這些值超過一氣呵成複製的辦法,比如說使用memcopy來獲得更多速度。
整個代碼爲:
extern "C" __declspec(dllexport) int __stdcall GetCameraImage(BYTE pBuffer[], int Type, int uWidth, int uHeight)
{
CameraImage Image;
int ret;
Image.pVid = (unsigned int*)malloc(4 * uWidth*uHeight);
ret = stGetCameraImage(&Image, 1, uWidth, uHeight);
if (ret == ERR_SUCCESS)
{
int iLen = (4 * uWidth * uHeight);
for (int i = 0; i < (iLen + 1); i++)
{
*(pBuffer + i) = Image.pVid[i];
}
////print(「ImageType = %d, width = %d, height = %d」, Image.Type, Image.Width,
//// Image.Height);
////print(「First Pixel : B = %d, G = %d, R = %d」, Image.pVid[0], Image.pVid[1],
//// Image.pVid[2]);
////print(「Second Pixel : B = %d, G = %d, R = %d」, Image.pVid[4], Image.pVid[5],
//// Image.pVid[6]);
}
free(Image.pVid);
return ret;
}
編輯:
* PVID是這樣的:
unsigned int *pVid; // pointer to image data (Format RGB32...)
你確定'我<(iLen + 1);'? – 2014-12-05 00:53:08
不太確定。應該是我<艾倫? – tmighty 2014-12-05 00:54:24
這有點不清楚:你想複製一個字節一個字節嗎?換句話說,pBuffer的大小是多少:與Image中相同的項目數量或相同的字節數量? – 2014-12-05 00:55:47