Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
TemplateAllocator.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_TEMPLATE_ALLOCATOR_H_
34#define DVD_TEMPLATE_ALLOCATOR_H_
35
36#include <EASTL/internal/config.h>
37
38template<class T>
39using dvd_allocator = mi_stl_allocator<T>;
40
41namespace eastl
42{
43 inline allocator::allocator( const char* EASTL_NAME( pName ) )
44 {
45#if EASTL_NAME_ENABLED
46 mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME;
47#endif
48 }
49
50
51 inline allocator::allocator( const allocator& EASTL_NAME( alloc ) )
52 {
53#if EASTL_NAME_ENABLED
54 mpName = alloc.mpName;
55#endif
56 }
57
58
59 inline allocator::allocator( const allocator&, const char* EASTL_NAME( pName ) )
60 {
61#if EASTL_NAME_ENABLED
62 mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME;
63#endif
64 }
65
66
67 inline allocator& allocator::operator=( const allocator& EASTL_NAME( alloc ) )
68 {
69#if EASTL_NAME_ENABLED
70 mpName = alloc.mpName;
71#endif
72 return *this;
73 }
74
75
76 inline const char* allocator::get_name() const
77 {
78#if EASTL_NAME_ENABLED
79 return mpName;
80#else
81 return EASTL_ALLOCATOR_DEFAULT_NAME;
82#endif
83 }
84
85
86 inline void allocator::set_name( const char* EASTL_NAME( pName ) )
87 {
88#if EASTL_NAME_ENABLED
89 mpName = pName;
90#endif
91 }
92
93
94 inline void* allocator::allocate( size_t n, [[maybe_unused]] int flags )
95 {
96#if EASTL_NAME_ENABLED
97#define pName mpName
98#else
99#define pName EASTL_ALLOCATOR_DEFAULT_NAME
100#endif
101 return mi_new( n );
102 }
103
104
105 inline void* allocator::allocate( size_t n, size_t alignment, [[maybe_unused]] size_t offset, [[maybe_unused]] int flags )
106 {
107 return mi_new_aligned(n, alignment);
108#undef pName // See above for the definition of this.
109 }
110
111
112 inline void allocator::deallocate( void* p, size_t )
113 {
114 mi_free(p);
115 }
116
117
118 inline bool operator==( const allocator&, const allocator& )
119 {
120 return true; // All allocators are considered equal, as they merely use global new/delete.
121 }
122
123#if !defined(EA_COMPILER_HAS_THREE_WAY_COMPARISON)
124 inline bool operator!=( const allocator&, const allocator& )
125 {
126 return false; // All allocators are considered equal, as they merely use global new/delete.
127 }
128#endif
129
130} // namespace eastl
131
132#endif //DVD_TEMPLATE_ALLOCATOR_H_
#define pName
mi_stl_allocator< T > dvd_allocator
bool operator==(const allocator &, const allocator &)
bool operator!=(const allocator &, const allocator &)