I have a project where I need to process large chunks of data that can be coming either from a file or from memory. I figured the easiest way to abstract this is to use a std::istream&.
This will work well for files. However, for the in-memory situation, it appears that I need to create a std::string and use the std::string to create a std::istringstream. As I read through the reference material on this site, it appears that both the construction of the std::string and std::istringstream cause the memory to be copied. I don't have numbers, yet, but based on the large amounts of data to be processed, I am concerned about the performance hit of the 2 unnecessary copies, as well as the amount of memory being consumed.
The simplest solution would be to have 2 separate functions, 1 for streams and one for uint8_t*, but that would require maintenance overhead. Is it possible to create an istream from a uint8_t* buffer without copies?
You can easily take any old stream you want and replace its streambuffer with your own custom streambuffer. You will have to research into how to write your own streambuffer: http://www.mr-edd.co.uk/blog/beginners_guide_streambuf
This might be overkill - I just don't know if there is already a simple answer to your question.