I would like to share a large data file (>100Mb)
for read between several processes. Each process is C++
based and suppose to read the file using std::vector
data type.
For the sharing part, a suitable methodology would be to use the mmap
syscall with MAP_SHARED
and PROT_READ
configuration.
However, I'd like to map this data to std::vector<uint32_t>
without data copying. Is there any std::vector
constructor I can use to initialize it by pointing an existing range of memory ?
EDIT: seems like I can implement special allocator for std::vector that instead of allocating new vector and resizing it to the mapped memory, can simply set this region in construction time. Perhaps anybody can show me how to implement such an allocator.
In addition, when mapping a file to memory the default data allocation is lazy, which means that memory isn't actually read from the file unless being asked for. In my approach I'd like to read the entire file in advance. Is there any mmap
flag to do so ?
EDIT: using MAP_POPULATE with mmap resolve the lazy file reading and allow read-ahead the data.
Aucun commentaire:
Enregistrer un commentaire