I have a large file containing strings. I have to read this file and store it in a buffer using C or C++. I tried to do it as follows:
FILE* file = fopen(fileName.c_str(), "r");
assert(file != NULL);
size_t BUF_SIZE = 10 * 1024 * 1024;
char* buf = new char[BUF_SIZE];
string contents;
while (!feof(file))
{
int ret = fread(buf, BUF_SIZE, 1, file);
assert(ret != -1);
contents.append(buf);
}
The data in the file would be the strings and i have to find the character with maximum frequency. Is it possible to optimize the code more than this ? Will using BinaryReader improve optimisation ? Could you share some more ways if you know?