Repository navigation
Expand file tree
/
Copy pathstatic_buffer.h
More file actions
68 lines (58 loc) · 1.56 KB
/
Copy pathstatic_buffer.h
File metadata and controls
68 lines (58 loc) · 1.56 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
////////////////////////////////////////////////////////////////////////////////
// Distributed under the Boost Software License, Version 1.0. //
// (See accompanying file LICENSE or copy at //
// https://www.boost.org/LICENSE_1_0.txt) //
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cstddef>
#include <cstdint>
#include <memory>
#include <set>
namespace iris
{
/**
* Fixed size managed buffer. Memory is allocated in pages and is read-writable.
* Guard pages are also allocated before and after the memory region, so
* out-of-bounds access fails fast and loud.
*/
class StaticBuffer
{
public:
/**
* Create buffer with requested number of pages.
*
* @param pages
* Number of pages to allocate.
*/
explicit StaticBuffer(std::size_t pages);
/**
* Release all allocated memory.
*/
~StaticBuffer();
/**
* Get page size in bytes.
*
* @returns
* Number of bytes in a page.
*/
static std::size_t page_size();
/**
* Get start of allocated buffer.
*
* @returns
* Pointer to start of buffer.
*/
operator std::byte *() const;
/**
* Number of allocated bytes. This does not include any guard pages.
*
* @returns
* Number of allocated bytes.
*/
std::size_t size() const;
private:
/** Pointer to implementation. */
struct implementation;
std::unique_ptr<implementation> impl_;
};
}