I have what I believe is a simple question about the std::vector type. The underlying problem is straightforward: I have a function that reads a stream of data into a buffer (as well as getting the buffer's size), then returns a that data as a vector. The type for the collection elements is fixed, uint8_t. My question is, is there a better way for me to populate the vector than walking the buffer?
Here is my naive, harebrained code:
uint8_t* buffer;
size_t size;
stream->readBuffer(buffer, size); // I don't own the stream class
std::vector<uint8_t> output(size);
for (size_t i = 0; i < currentChunkLength; i++)
{
output.push_back(buffer[i]);
}
return output;