Cogs.Core
StdAllocator.h
1#pragma once
2
3#include "Allocator.h"
4
5namespace Cogs
6{
7 namespace Memory
8 {
9 template<typename T>
11 {
12 public:
13 using value_type = T;
14 using pointer = T *;
15 using size_type = size_t;
16
17 StdAllocator() = default;
18 StdAllocator(Allocator * allocator) : allocator(allocator) {}
19
20 template<typename U>
21 StdAllocator(const StdAllocator<U> & other) : allocator(other.allocator) {}
22
23 pointer allocate(size_type n)
24 {
25 return static_cast<pointer>(allocator->allocate(n * sizeof(T)));
26 }
27
28 void deallocate(pointer p, size_type n)
29 {
30 allocator->deallocate(p, n * sizeof(T));
31 }
32
33 private:
35
36 template<typename U> friend class StdAllocator;
37 };
38 }
39}
Base allocator implementation.
Definition: Allocator.h:30
static Allocator * defaultAllocator()
Gets the system default allocator.
Definition: Allocator.cpp:17
virtual void deallocate(void *ptr, size_t size, MemBlockType type=MemBlockType::Block)
Deallocate the memory block at the given pointer, with the given size.
Definition: Allocator.cpp:58
virtual void * allocate(size_t size, size_t alignment=0, MemBlockType type=MemBlockType::Block)
Allocate raw memory.
Definition: Allocator.cpp:29
Contains all Cogs related functionality.
Definition: FieldSetter.h:23