mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Allow configuring the BumpAllocator chunk size
This commit is contained in:
parent
510bbcd8e0
commit
dae7674ca9
Notes:
sideshowbarker
2024-07-18 07:30:45 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/dae7674ca98 Pull-request: https://github.com/SerenityOS/serenity/pull/9177
1 changed files with 10 additions and 8 deletions
|
@ -13,15 +13,15 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<bool use_mmap = false>
|
||||
template<bool use_mmap = false, size_t chunk_size = use_mmap ? 4 * MiB : 4 * KiB>
|
||||
class BumpAllocator {
|
||||
public:
|
||||
BumpAllocator()
|
||||
{
|
||||
if constexpr (use_mmap)
|
||||
m_chunk_size = 4 * MiB;
|
||||
m_chunk_size = chunk_size;
|
||||
else
|
||||
m_chunk_size = kmalloc_good_size(4 * KiB);
|
||||
m_chunk_size = kmalloc_good_size(chunk_size);
|
||||
}
|
||||
|
||||
~BumpAllocator()
|
||||
|
@ -137,8 +137,10 @@ protected:
|
|||
// size_t m_allocations_in_previous_chunk { 0 };
|
||||
};
|
||||
|
||||
template<typename T, bool use_mmap = false>
|
||||
class UniformBumpAllocator : protected BumpAllocator<use_mmap> {
|
||||
template<typename T, bool use_mmap = false, size_t chunk_size = use_mmap ? 4 * MiB : 4 * KiB>
|
||||
class UniformBumpAllocator : protected BumpAllocator<use_mmap, chunk_size> {
|
||||
using Allocator = BumpAllocator<use_mmap, chunk_size>;
|
||||
|
||||
public:
|
||||
UniformBumpAllocator() = default;
|
||||
~UniformBumpAllocator()
|
||||
|
@ -148,19 +150,19 @@ public:
|
|||
|
||||
T* allocate()
|
||||
{
|
||||
return BumpAllocator<use_mmap>::template allocate<T>();
|
||||
return Allocator::template allocate<T>();
|
||||
}
|
||||
|
||||
void deallocate_all()
|
||||
{
|
||||
destroy_all();
|
||||
BumpAllocator<use_mmap>::deallocate_all();
|
||||
Allocator::deallocate_all();
|
||||
}
|
||||
|
||||
void destroy_all()
|
||||
{
|
||||
this->for_each_chunk([&](auto chunk) {
|
||||
auto base_ptr = align_up_to(chunk + sizeof(typename BumpAllocator<use_mmap>::ChunkHeader), alignof(T));
|
||||
auto base_ptr = align_up_to(chunk + sizeof(typename Allocator::ChunkHeader), alignof(T));
|
||||
FlatPtr end_offset = this->m_chunk_size;
|
||||
if (chunk == this->m_current_chunk)
|
||||
end_offset = this->m_byte_offset_into_current_chunk;
|
||||
|
|
Loading…
Reference in a new issue