2016-08-06 20:41:00 +01:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2016 MerryMage
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
|
|
|
* General Public License version 2 or any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Dynarmic {
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
class Pool {
|
|
|
|
public:
|
2016-08-12 18:17:31 +01:00
|
|
|
/**
|
|
|
|
* @param object_size Byte-size of objects to construct
|
|
|
|
* @param initial_pool_size Number of objects to have per slab
|
|
|
|
*/
|
2016-08-06 20:41:00 +01:00
|
|
|
Pool(size_t object_size, size_t initial_pool_size);
|
|
|
|
~Pool();
|
|
|
|
|
|
|
|
Pool(Pool&) = delete;
|
|
|
|
Pool(Pool&&) = delete;
|
|
|
|
|
2016-08-12 18:17:31 +01:00
|
|
|
/// Returns a pointer to an `object_size`-bytes block of memory.
|
2016-08-06 20:41:00 +01:00
|
|
|
void* Alloc();
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t object_size;
|
|
|
|
size_t slab_size;
|
|
|
|
char* current_slab;
|
|
|
|
char* current_ptr;
|
|
|
|
size_t remaining;
|
|
|
|
std::vector<char*> slabs;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Common
|
|
|
|
} // namespace Dynarmic
|