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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With