Custom 1 MB file stream buffers?

The code below may, or may not, end up in the LZW article I'm currently working on.

I need you to tell me if this is stupid, and if so, why. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstddef>
#include <fstream>
#include <ios>
#include <memory>

// ...

const std::size_t one_mb = 1024 * 1024; // one megabyte
const std::unique_pointer<char[]> custom_buffer(new char[one_mb]);
std::fstream f; // must set the custom buffer before opening the file

f.rdbuf()->pubsetbuf(custom_buffer.get(), one_mb);
f.open("file.txt", std::ios_base::in | std::ios_base::binary);

Topic archived. No new replies allowed.