mmap - The best way to process a large amount of data that is stored in a file if you want to get random access to this data.
mmap , , . , . , , , , , ( ) .
:
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h> /* the header where mmap is defined */
#include <fcntl.h>
int file;
char *contents;
struct stat statbuf;
off_t len;
file = open("path/to/file", O_RDONLY);
if (file < 0)
exit(1);
if (fstat(file, &statbuf) < 0)
exit(1);
len = statbuf.st_size;
contents = mmap(0, len, PROT_READ, MAP_SHARED, file, 0);
if (contents == MAP_FAILED)
exit(1);
munmap(contents, len);
close(file);