2020-07-11 12:34:23 +02:00
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include "pool.h"
|
2020-07-11 17:36:05 +02:00
|
|
|
#include <limits>
|
2020-07-11 12:34:23 +02:00
|
|
|
namespace T5M::Memory {
|
|
|
|
template <typename T,typename Pool>
|
|
|
|
class PoolAllocator {
|
|
|
|
|
|
|
|
public:
|
|
|
|
Pool* pool;
|
|
|
|
typedef std::size_t size_type;
|
|
|
|
typedef T* pointer;
|
|
|
|
typedef T value_type;
|
|
|
|
|
|
|
|
PoolAllocator(Pool* pool) : pool(pool) {}
|
|
|
|
|
|
|
|
PoolAllocator(const PoolAllocator& other) throw() : pool(other.pool) {};
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
PoolAllocator(const PoolAllocator<U,Pool>& other) throw() : pool(other.pool) {};
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
PoolAllocator& operator = (const PoolAllocator<U,Pool>& other) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
PoolAllocator<T,Pool>& operator = (const PoolAllocator& other) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
~PoolAllocator() {}
|
|
|
|
|
|
|
|
pointer allocate(size_type n, const void* hint = 0) {
|
2020-07-11 17:36:05 +02:00
|
|
|
return (pool)->malloc<value_type>(n);
|
2020-07-11 12:34:23 +02:00
|
|
|
}
|
|
|
|
void deallocate(T* ptr, size_type n) {
|
2020-07-11 17:36:05 +02:00
|
|
|
(pool)->free(ptr);
|
2020-07-11 12:34:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_type max_size() const {
|
|
|
|
#pragma push_macro("max") //thanks Microsoft
|
|
|
|
#undef max
|
2020-07-11 17:36:05 +02:00
|
|
|
return std::numeric_limits<size_type>::max();
|
2020-07-11 12:34:23 +02:00
|
|
|
#pragma pop_macro("max")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|