Archived Forum Post

Index of archived forum posts

Question:

How fast convert std::vector to CkByteData?

Nov 01 '16 at 10:53

Hello.

I am using C++11 standart. Application based to std::vector<unsigned char=""> (unsigned char == BYTE in Windows).

Question: How fast convert std::vector<unsigned char=""> to CkByteData?


My convertion code (slow speed):

std::vector<unsigned char> inputBuffer = { 0x01, 0x02, 0x03 };
CkByteData buffer;
for (int i = 0; i < (int)inputBuffer.size(); i++)
    buffer.appendChar(inputBuffer[i]);

Answer

Another way:

buffer.append2(&inputBuffer[0], (unsigned long)inputBuffer.size());