Skip to content

Commit 81f44c5

Browse files
Merge pull request #1179 from AnyOldName3/allocator-adapter
Support other affinities for the STL allocator adapter
2 parents 8a36e8b + 7f95c06 commit 81f44c5

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

include/vsg/core/Allocator.h

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,25 @@ namespace vsg
136136
/// deallocate memory using vsg::Allocator::instance() if available, otherwise use std::free(ptr)
137137
extern VSG_DECLSPEC void deallocate(void* ptr, std::size_t size = 0);
138138

139-
/// std container adapter for allocating with MEMORY_AFFINITY_NODES
140-
template<typename T>
141-
struct allocator_affinity_nodes
139+
/// std container adapter for allocating with specific affinity
140+
template<typename T, vsg::AllocatorAffinity A>
141+
struct allocator_affinity_adapter
142142
{
143143
using value_type = T;
144144

145-
allocator_affinity_nodes() = default;
145+
allocator_affinity_adapter() = default;
146+
template<class U>
147+
explicit constexpr allocator_affinity_adapter(const allocator_affinity_adapter<U, A>&) noexcept {}
148+
146149
template<class U>
147-
explicit constexpr allocator_affinity_nodes(const allocator_affinity_nodes<U>&) noexcept {}
150+
struct rebind
151+
{
152+
using other = allocator_affinity_adapter<U, A>;
153+
};
148154

149155
value_type* allocate(std::size_t n)
150156
{
151-
return static_cast<value_type*>(vsg::allocate(n * sizeof(value_type), vsg::ALLOCATOR_AFFINITY_NODES));
157+
return static_cast<value_type*>(vsg::allocate(n * sizeof(value_type), A));
152158
}
153159

154160
void deallocate(value_type* ptr, std::size_t n)
@@ -157,10 +163,19 @@ namespace vsg
157163
}
158164
};
159165

160-
template<class T, class U>
161-
bool operator==(const allocator_affinity_nodes<T>&, const allocator_affinity_nodes<U>&) { return true; }
166+
template<class T, class U, vsg::AllocatorAffinity A>
167+
bool operator==(const allocator_affinity_adapter<T, A>&, const allocator_affinity_adapter<U, A>&) { return true; }
162168

163-
template<class T, class U>
164-
bool operator!=(const allocator_affinity_nodes<T>&, const allocator_affinity_nodes<U>&) { return false; }
169+
template<class T, class U, vsg::AllocatorAffinity A>
170+
bool operator!=(const allocator_affinity_adapter<T, A>&, const allocator_affinity_adapter<U, A>&) { return false; }
171+
172+
template<typename T>
173+
using allocator_affinity_objects = allocator_affinity_adapter<T, vsg::ALLOCATOR_AFFINITY_OBJECTS>;
174+
template<typename T>
175+
using allocator_affinity_data = allocator_affinity_adapter<T, vsg::ALLOCATOR_AFFINITY_DATA>;
176+
template<typename T>
177+
using allocator_affinity_nodes = allocator_affinity_adapter<T, vsg::ALLOCATOR_AFFINITY_NODES>;
178+
template<typename T>
179+
using allocator_affinity_physics = allocator_affinity_adapter<T, vsg::ALLOCATOR_AFFINITY_PHYSICS>;
165180

166181
} // namespace vsg

0 commit comments

Comments
 (0)