-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39ebd8e
commit aa5f35c
Showing
4 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <type_traits> | ||
|
||
template <class T> | ||
struct HostAllocator; | ||
|
||
struct MemorySpace | ||
{ | ||
}; | ||
|
||
template <class T> | ||
constexpr inline bool is_memory_space = std::is_base_of_v<MemorySpace, T>; | ||
|
||
struct HostMemorySpace : MemorySpace | ||
{ | ||
template <class T> | ||
using default_allocator_type = HostAllocator<T>; | ||
}; | ||
|
||
template <class Memory, class T> | ||
using DefaultAllocator_t = typename Memory::template default_allocator_type<T>; | ||
|
||
template <class T> | ||
class HostAllocator | ||
{ | ||
public: | ||
using value_type = T; | ||
using memory_space_type = HostMemorySpace; | ||
|
||
constexpr HostAllocator() = default; | ||
|
||
constexpr HostAllocator(HostAllocator const& x) = default; | ||
|
||
constexpr HostAllocator(HostAllocator&& x) noexcept = default; | ||
|
||
~HostAllocator() = default; | ||
|
||
constexpr HostAllocator& operator=(HostAllocator const& x) = default; | ||
|
||
constexpr HostAllocator& operator=(HostAllocator&& x) noexcept = default; | ||
|
||
[[nodiscard]] T* allocate(std::size_t n) | ||
{ | ||
return new (std::align_val_t(64)) value_type[n]; | ||
} | ||
|
||
void deallocate(T* p, std::size_t) | ||
{ | ||
operator delete[](p, std::align_val_t(64)); | ||
} | ||
}; |