1#pragma once
2
3#include <IO/ReadBuffer.h>
4
5
6namespace DB
7{
8
9/** MMap range in a file and represent it as a ReadBuffer.
10 * Please note that mmap is not always the optimal way to read file.
11 * Also you cannot control whether and how long actual IO take place,
12 * so this method is not manageable and not recommended for anything except benchmarks.
13 */
14class MMapReadBufferFromFileDescriptor : public ReadBuffer
15{
16protected:
17 MMapReadBufferFromFileDescriptor() : ReadBuffer(nullptr, 0) {}
18
19 void init(int fd_, size_t offset, size_t length_);
20 void init(int fd_, size_t offset);
21
22public:
23 MMapReadBufferFromFileDescriptor(int fd_, size_t offset_, size_t length_);
24
25 /// Map till end of file.
26 MMapReadBufferFromFileDescriptor(int fd_, size_t offset_);
27
28 ~MMapReadBufferFromFileDescriptor() override;
29
30 /// unmap memory before call to destructor
31 void finish();
32
33private:
34 size_t length = 0;
35 int fd = -1;
36};
37
38}
39
40