So basically I'm looking for functionality akin to std::ifstream and std::ofstream, but instead of writing\reading a file I want to write\read memory.
For instance, for writing, I would like to avoid having to malloc, realloc, and whatnot myself and have a stream and be able to do something like this:
For each write call, it would do all the memory allocation it needs and I wouldn't have to worry about it. Then when I'm done writing that data, I can either copy it and free the data in the stream, or save a pointer to the data and just "close" the stream.
Someone on this forum (I don't remember who) provided a way to use streams based on char* memory buffers. This is only for fixed-size buffers, but you could modify this to do the allocation / reallocation that will be necessary.
Note: I modified for my own purposes the code that was originally presented. I think I removed all of my own specific code, so this should be what was originally presented.