Reputation: 31
The only two requirements I'm limited to is that it must be OS independent and that the data is not saved as binary, I need to save it as text. I've heard of memory mapping, but I'm told I can only use it on windows. Currently, my program's speed is being mainly held back by how fast I can load a file, so any help would be appreciated. So far, this is the best solution I've come to.
std::ifstream file(filepath);
fileContents.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
Upvotes: 0
Views: 74
Reputation: 15164
Speed and OS-agnostism are pretty much mutually exclusive. As the comment says, all major OSes offer memory mapping but the way they offer it will vary. Windows has CreateFileMapping while posix systems have mmap.
It would not surprise me if boost has a component library that glosses over these differences but I could not tell you which library that would be.
Of course there is also the whole "premature optimization is the root of all evil" thing to consider, are you sure that what the standard library offers is not "good enough"?
Upvotes: 1