itch-mold-replay 1.0
Time-accurate NASDAQ TotalView-ITCH 5.0 replay over MoldUDP64
Loading...
Searching...
No Matches
memory_mapped_file.h
Go to the documentation of this file.
1#pragma once
2
3#include "imr/util/file_descriptor.h"
4
5#include <sys/mman.h>
6#include <span>
7
8namespace imr::util
9{
10 /** RAII mmap file
11
12 Read only so PROT_READ and only returns const span view
13 */
15 {
16 public:
17 /// @ingroup config
18 struct Config
19 {
20 /**
21 Path of the file to map
22
23 @throws std::invalid_argument if invalid path or directory
24 @throws std::system_error if open() fails
25 */
26 std::filesystem::path path;
27 /**
28 Additional mmap() flags, OR'd with MAP_PRIVATE.
29
30 MAP_PRIVATE is always used since the mapping is read only, but you can pass additional flags via this.
31 */
32 int mmap_flags{0};
33 /// Flags passed to madvise() after mapping. Pass 0 to skip madvise() call entirely.
35 };
36
37 explicit MemoryMappedFile(const Config& cfg);
38
41
44
46
47 [[nodiscard]]
48 std::span<const char> as_span() const noexcept;
49
50 private:
52 std::size_t length_{0};
53 void* mapped_file_{nullptr};
54
55 void cleanup() noexcept;
56 };
57}
RAII file descriptor wrapper.
Definition file_descriptor.h:19
RAII mmap file.
Definition memory_mapped_file.h:15
MemoryMappedFile & operator=(MemoryMappedFile &&other) noexcept
MemoryMappedFile(const MemoryMappedFile &)=delete
MemoryMappedFile(const Config &cfg)
MemoryMappedFile(MemoryMappedFile &&other) noexcept
std::span< const char > as_span() const noexcept
MemoryMappedFile & operator=(const MemoryMappedFile &)=delete
Definition file_descriptor.h:11
Definition memory_mapped_file.h:19
int mmap_flags
Additional mmap() flags, OR'd with MAP_PRIVATE.
Definition memory_mapped_file.h:32
int madvise_flags
Flags passed to madvise() after mapping. Pass 0 to skip madvise() call entirely.
Definition memory_mapped_file.h:34