Cogs.Foundation
Loading...
Searching...
No Matches
MemTypeAllocator.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <OsoMemoryProfiler/CogsMemoryProfile.h>
5
6namespace Cogs::Memory
7{
8
14 template<class T, Cogs::MemBlockType memType>
16 {
17 std::allocator<T> alloc;
18
19 using value_type = T;
20 using pointer = T*;
21 using size_type = typename std::allocator<T>::size_type;
22
23 MemTypeAllocator() = default;
24
25 MemTypeAllocator(const MemTypeAllocator& other) : alloc(std::allocator<T>(other.alloc)) { }
26
27 template<typename U>
29
31 {
32 pointer p = alloc.allocate(n);
33 if (p) {
34 OsoMP_Allocate(uint8_t(memType), p, n, nullptr, 0);
35 }
36 return p;
37 }
38
40 {
41 if (p) {
42 OsoMP_Free(uint8_t(memType), p, nullptr, 0);
43 }
44 alloc.deallocate(p, n);
45 }
46
47 template<typename U>
49 };
50
51 template<class T1, Cogs::MemBlockType memType1, class T2, Cogs::MemBlockType memType2>
53 {
54 return memType1 == memType2 && lhs.alloc == rhs.alloc;
55 }
56}
Definition: Allocator.h:14
bool operator==(const MemTypeAllocator< T1, memType1 > &lhs, const MemTypeAllocator< T2, memType2 > &rhs) noexcept
Definition: MemTypeAllocator.h:52
STL namespace.
Definition: MemTypeAllocator.h:48
MemTypeAllocator< U, memType > other
Definition: MemTypeAllocator.h:48
Definition: MemTypeAllocator.h:16
std::allocator< T > alloc
Definition: MemTypeAllocator.h:17
pointer allocate(size_type n)
Definition: MemTypeAllocator.h:30
T * pointer
Definition: MemTypeAllocator.h:20
MemTypeAllocator(const MemTypeAllocator< U, memType > &other)
Definition: MemTypeAllocator.h:28
T value_type
Definition: MemTypeAllocator.h:19
typename std::allocator< T >::size_type size_type
Definition: MemTypeAllocator.h:21
void deallocate(T *p, size_type n)
Definition: MemTypeAllocator.h:39
MemTypeAllocator(const MemTypeAllocator &other)
Definition: MemTypeAllocator.h:25