mio
1.1.0
Loading...
Searching...
No Matches
page.hpp
Go to the documentation of this file.
1
/* Copyright 2017 https://github.com/mandreyel
2
*
3
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
* software and associated documentation files (the "Software"), to deal in the Software
5
* without restriction, including without limitation the rights to use, copy, modify,
6
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7
* permit persons to whom the Software is furnished to do so, subject to the following
8
* conditions:
9
*
10
* The above copyright notice and this permission notice shall be included in all copies
11
* or substantial portions of the Software.
12
*
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
15
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
16
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
18
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
*/
20
21
/*
22
* Copyright 2026 Maxtek Consulting
23
*
24
* Permission is hereby granted, free of charge, to any person obtaining a copy
25
* of this software and associated documentation files (the "Software"), to deal
26
* in the Software without restriction, including without limitation the rights
27
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28
* copies of the Software, and to permit persons to whom the Software is
29
* furnished to do so, subject to the following conditions:
30
*
31
* The above copyright notice and this permission notice shall be included in all
32
* copies or substantial portions of the Software.
33
*
34
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
* SOFTWARE.
41
*/
42
43
#ifndef MIO_PAGE_HPP
44
#define MIO_PAGE_HPP
45
46
#ifdef _WIN32
47
#include <windows.h>
48
#else
49
#include <unistd.h>
50
#endif
51
52
namespace
mio
{
53
58
enum class
access_mode
59
{
60
read
,
61
write
62
};
63
70
inline
size_t
page_size
() {
71
static
const
size_t
page_size
= [] {
72
#ifdef _WIN32
73
SYSTEM_INFO SystemInfo;
74
GetSystemInfo(&SystemInfo);
75
return
SystemInfo.dwAllocationGranularity;
76
#else
77
return
sysconf(_SC_PAGE_SIZE);
78
#endif
79
}();
80
return
page_size
;
81
}
82
88
inline
size_t
make_offset_page_aligned
(
size_t
offset)
noexcept
{
89
const
size_t
page_size_ =
page_size
();
90
// Use integer division to round down to the nearest page alignment.
91
return
offset / page_size_ * page_size_;
92
}
93
94
};
// namespace mio
95
96
#endif
// MIO_PAGE_HPP
mio
Definition
string_util.hpp:48
mio::access_mode
access_mode
Definition
page.hpp:59
mio::access_mode::read
@ read
mio::access_mode::write
@ write
mio::page_size
size_t page_size()
Definition
page.hpp:70
mio::make_offset_page_aligned
size_t make_offset_page_aligned(size_t offset) noexcept
Definition
page.hpp:88
include
mio
page.hpp
Generated by
1.9.8