35 lines
678 B
C++
35 lines
678 B
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cstddef>
|
|
#include <cstring>
|
|
#include <exception>
|
|
#include <thread>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
template<class T>
|
|
concept resetable = requires(T val) {
|
|
val.reset();
|
|
};
|
|
|
|
template<class T>
|
|
requires std::default_initializable<T> && resetable<T>
|
|
class allocPool {
|
|
public:
|
|
explicit allocPool(size_t defaultAllocNumbers = 1000);
|
|
|
|
T *getPtr();
|
|
void returnPtr(T *ptr);
|
|
|
|
private:
|
|
std::vector<T *> vec;
|
|
std::unordered_map<T *, size_t> positionMap;
|
|
size_t pivot;
|
|
|
|
void initArray(size_t amount);
|
|
void initObjects(size_t startIdx, size_t amount);
|
|
void resizeVec();
|
|
};
|