What is the correct way to deal with medium-sized byte arrays in modern C++?
c++, c++11
Solution
You can use `std::vector<unsigned char>`, or as @Oli suggested `std::vector<uint8_t>`. Yes, you can pass around it, without copying the whole contents.
void f(std::vector<unsigned char> & byteArray) //pass by reference : no copy!
{
//
}
std::vector<unsigned char> byteArray;
//...
f(byteArray); //no copying is being made!
Problem
Many languages and frameworks offer a "byte array" type, but the C++ standard library does not. What type is appropriate to use for medium-sized1, resizable byte arrays and how can I use that type efficiently? (particularly: allocating, passing as parameters and destroying) 1: By medium-sized I mean less than a 100 MB.