Binary data? Stop using std :: string and use std::vector<char> . But this will not solve your copy problem. From your description, if this huge 64 MB buffer never changes, you really shouldn't use std :: string or std::vector<char> , or it's not a good idea. You really should go around the const char * pointer (const uint8_t * will be more descriptive of binary data, but under covers it's the same thing, ignoring sign issues). Skip the pointer and the length of size_t, or pass the pointer to another end pointer. If you do not like to go around individual discrete variables (pointer and buffer length), create a structure to describe the buffer and ask everyone to use them instead:
struct binbuf_desc { uint8_t* addr; size_t len; binbuf_desc(addr,len) : addr(addr), len(len) {} }
You can always reference your 64 MB buffer (or any other buffer of any size) using binbuf_desc objects. Note that binbuf_desc objects do not own the buffer (or its copy), but simply a descriptor, so you can simply pass them everywhere without worrying that binbuf_descs creates unnecessary copies of the buffer.
source share