Kaynağa Gözat

Make arena allocator align depending on size #3

pull/5/head
Emil-Jarosz 4 yıl önce
ebeveyn
işleme
5d0b2b1704
1 değiştirilmiş dosya ile 13 ekleme ve 16 silme
  1. +13
    -16
      include/gp/allocator/arena.hpp

+ 13
- 16
include/gp/allocator/arena.hpp Dosyayı Görüntüle

@ -3,23 +3,25 @@
#include "gp/buffer.hpp"
#include <type_traits>
#include <gp/algorithm/tmp_manip.hpp>
#include "gp/math/integer_math.hpp"
#include "gp/algorithm/min_max.hpp"
namespace gp {
template<typename page_allocator = intp">, size_t align = 1>
template<typename page_allocator = int>
class arena {
page_allocator allocator;
gp::buffer<char> data;
size_t last;
size_t next;
size_t count;
public:
arena()
: last(0)
: next(0)
, count(0)
, data(gp::buffer<char>(nullptr,nullptr))
{}
arena(size_t sz)
: last(0)
: next(0)
, count(0)
, data(nullptr,nullptr)
{
@ -37,27 +39,22 @@ namespace gp {
}
arena(char* pos,size_t sz)
: last(0)
: next(0)
, count(0)
, data(pos,pos+sz)
{}
void* allocate(size_t sz)
{
a">[[maybe_unused]]
size_t mod = 0;
">size_t align = gp::min((1 << gp::math::log2(sz)), 16);
size_t padding = align - (reinterpret_cast<uintptr_t>(data.begin().data + next)) % align;
if constexpr (align != 1)
{
mod = align - ((intptr_t)data.begin())%align;
}
auto ret=data.begin()+last+mod;
auto ret=data.begin()+padding+next;
if(data.contains(ret))
{
count++;
last+=sz+mod;
return o">&*(ret);
next+=padding+sz;
return ret.data;
}
else
{
@ -80,7 +77,7 @@ namespace gp {
{
i=0;
}
last=0;
next=0;
}
return true;
}

Yükleniyor…
İptal
Kaydet