-
Notifications
You must be signed in to change notification settings - Fork 59
/
gpage_allocator.h
76 lines (59 loc) · 1.92 KB
/
gpage_allocator.h
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
69
70
71
72
73
74
75
76
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2016 Herb Sutter. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef GALLOC_GPAGE_ALLOCATOR
#define GALLOC_GPAGE_ALLOCATOR
#include "gpage.h"
namespace gcpp {
//----------------------------------------------------------------------------
//
// gpage_allocator - wrap a gpage as a C++14 allocator, with thanks to
// Howard Hinnant's allocator boilerplate exemplar code, online at
// https://howardhinnant.github.io/allocator_boilerplate.html
//
//----------------------------------------------------------------------------
static gpage page;
template <class T>
class gpage_allocator {
public:
using value_type = T;
gpage_allocator() noexcept
{
}
template <class U>
gpage_allocator(gpage_allocator<U> const&) noexcept
{
}
value_type* allocate(std::size_t n) noexcept
{
return page.allocate<T>(n);
}
void deallocate(value_type* p, std::size_t) noexcept
{
return page.deallocate(p);
}
};
template <class T, class U>
bool operator==(gpage_allocator<T> const&, gpage_allocator<U> const&) noexcept
{
return true;
}
template <class T, class U>
bool operator!=(gpage_allocator<T> const& x, gpage_allocator<U> const& y) noexcept
{
return !(x == y);
}
}
#endif