aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/io/mapped_file_input.h
blob: 132c289cdd34b97cf0a5faa82807cfec7c67b93d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/data/input.h>

namespace vespalib {

/**
 * Abstract input backed by a memory-mapped file.
 **/
class MappedFileInput : public Input
{
private:
    int     _fd;
    char   *_data;
    size_t  _size;
    size_t  _used;
public:
    MappedFileInput(const vespalib::string &file_name);
    ~MappedFileInput();
    bool valid() const;
    Memory get() const { return Memory(_data, _size); }
    Memory obtain() override;
    Input &evict(size_t bytes) override;
};

} // namespace vespalib