emilib
mem_map.hpp
1 // By Emil Ernerfeldt 2014-2016
2 // LICENSE:
3 // This software is dual-licensed to the public domain and under the following
4 // license: you are granted a perpetual, irrevocable license to copy, modify,
5 // publish, and distribute this file as you see fit.
6 // HISTORY:
7 // Created in 2014 for Ghostel
8 
9 #pragma once
10 
11 #include <cstddef> // size_t
12 
13 namespace emilib {
14 
16 class MemMap
17 {
18 public:
19  MemMap() : _size(0), _data(nullptr) { }
20  explicit MemMap(const char* path); // Open for reading
21  ~MemMap();
22 
23  MemMap(MemMap&& o) : _size(o._size), _data(o._data)
24  {
25  o._size = 0;
26  o._data = nullptr;
27  }
28 
29  void operator=(MemMap&& o);
30 
31  size_t size() const { return _size; }
32  const void* data() const { return _data; }
33 
34 private:
35  MemMap(MemMap&) = delete;
36  MemMap& operator=(MemMap&) = delete;
37 
38  size_t _size;
39  void* _data;
40 };
41 
42 } // namespace emilib
43 
Memory-mapped file. Really fast way of reading stuff from disk.
Definition: mem_map.hpp:16
Definition: coroutine.hpp:18