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
|
|
|
|
|
2016-09-03 21:48:03 +01:00
|
|
|
#include <cstddef>
|
2016-08-06 20:41:00 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
namespace Dynarmic::Common {
|
2016-08-06 20:41:00 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2017-11-12 08:52:34 +00:00
|
|
|
Pool(const Pool&) = delete;
|
2016-08-06 20:41:00 +01:00
|
|
|
Pool(Pool&&) = delete;
|
|
|
|
|
2017-11-12 08:52:34 +00:00
|
|
|
Pool& operator=(const Pool&) = delete;
|
|
|
|
Pool& operator=(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:
|
2016-09-07 13:20:42 +01:00
|
|
|
// Allocates a completely new memory slab.
|
|
|
|
// Used when an entirely new slab is needed
|
|
|
|
// due the current one running out of usable space.
|
|
|
|
void AllocateNewSlab();
|
|
|
|
|
2016-08-06 20:41:00 +01:00
|
|
|
size_t object_size;
|
|
|
|
size_t slab_size;
|
|
|
|
char* current_slab;
|
|
|
|
char* current_ptr;
|
|
|
|
size_t remaining;
|
|
|
|
std::vector<char*> slabs;
|
|
|
|
};
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
} // namespace Dynarmic::Common
|