I want to use memory mapping files for data that I read only once. Currently I am using:
FILE * f = fopen("data.dat", "rb");
fseek(f, 0L, SEEK_END);
size_t fileSize = ftell(f);
fseek(f, 0L, SEEK_SET);
char * buffer = new char[fileSize];
fread(buffer, sizeof(char), fileSize, f);
fclose(f);
//operate with buffer
for (size_t i = 0; i < fileSize; i++){
//...
}
I wanted to use mmap and operate directly on mapped buffer. However, I have found in Apple doc about mmap
that there is:
You should not use file mapping in the following situations:
- You want to read a file sequentially from start to finish only once.
Why? If I use fread
there is more "logic", plus I am creating new array, that is also not for free.