Skip to content

Instantly share code, notes, and snippets.

@bagobor
Created January 20, 2016 13:41
Show Gist options
  • Save bagobor/c17228c05ee20ffbd7cb to your computer and use it in GitHub Desktop.
Save bagobor/c17228c05ee20ffbd7cb to your computer and use it in GitHub Desktop.
std::streambuff derived class for mem optimisations
class carray_streambuf : public std::streambuf {
public:
carray_streambuf(char *data, unsigned int len) {
setp(data, data+len);
setg(data, data, data + len);
}
// amount of stored (written!) data in bytes
size_t saved_bytes() const { return pptr() - pbase(); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment