xo-alloc2: implement alloc for obj<AAllocator,DArena>
This commit is contained in:
parent
1b1a2b5eab
commit
f2f10242ac
3 changed files with 47 additions and 20 deletions
|
|
@ -31,13 +31,13 @@ namespace xo {
|
|||
// from AAllocator
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
|
||||
[[noreturn]] const std::string & name(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type reserved(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type size(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type committed(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type available(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type allocated(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] bool contains(Copaque, const void *) const noexcept override { _fatal(); }
|
||||
[[noreturn]] const std::string & name(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type reserved(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type size(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type committed(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type available(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type allocated(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] bool contains(Copaque, const void *) const noexcept override { _fatal(); }
|
||||
[[noreturn]] AllocatorError last_error(Copaque) const noexcept override { _fatal(); }
|
||||
|
||||
[[noreturn]] bool expand(Opaque, std::size_t) const noexcept override { _fatal(); }
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace xo {
|
|||
**/
|
||||
static bool expand(DArena & d, std::size_t z) noexcept;
|
||||
|
||||
static std::byte * alloc(const DArena &, std::size_t z);
|
||||
static std::byte * alloc(DArena &, std::size_t z);
|
||||
static void clear(DArena &);
|
||||
static void destruct_data(DArena &);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace xo {
|
||||
using std::size_t;
|
||||
using std::byte;
|
||||
|
||||
namespace mm {
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ namespace xo {
|
|||
xtag("target_z", target_z),
|
||||
xtag("committed_z", s.committed_z_));
|
||||
|
||||
if (target_z <= s.committed_z_) {
|
||||
if (target_z <= s.committed_z_) [[likely]] {
|
||||
log && log("trivial success, offset within committed range",
|
||||
xtag("target_z", target_z),
|
||||
xtag("committed_z", s.committed_z_));
|
||||
|
|
@ -142,15 +143,41 @@ namespace xo {
|
|||
}
|
||||
|
||||
std::byte *
|
||||
IAllocator_DArena::alloc(const DArena & s,
|
||||
std::size_t z)
|
||||
IAllocator_DArena::alloc(DArena & s,
|
||||
std::size_t req_z)
|
||||
{
|
||||
(void)s;
|
||||
(void)z;
|
||||
scope log(XO_DEBUG(s.config_.debug_flag_));
|
||||
|
||||
// scope log(XO_DEBUG(config_.debug_flag_));
|
||||
/* word size for alignment (8 bytes) */
|
||||
constexpr size_t c_bpw = sizeof(std::uintptr_t);
|
||||
|
||||
assert(false);
|
||||
std::uintptr_t free_u64 = reinterpret_cast<std::uintptr_t>(s.free_);
|
||||
|
||||
assert(free_u64 % c_bpw == 0ul);
|
||||
|
||||
/* dz: pad req_z to multiple c_bpw */
|
||||
size_t dz = padding::alloc_padding(req_z);
|
||||
size_t z1 = req_z + dz;
|
||||
|
||||
assert(z1 % c_bpw == 0ul);
|
||||
|
||||
if (expand(s, allocated(s) + z1)) [[likely]] {
|
||||
byte * mem = s.free_;
|
||||
|
||||
s.free_ += z1;
|
||||
|
||||
log && log(xtag("self", s.config_.name_),
|
||||
xtag("z0", req_z),
|
||||
xtag("+pad", dz),
|
||||
xtag("z1", z1),
|
||||
xtag("size", size(s)),
|
||||
xtag("avail", available(s)));
|
||||
|
||||
return mem;
|
||||
} else {
|
||||
/* error already captured */
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -160,11 +187,11 @@ namespace xo {
|
|||
//s.checkpoint_ = s.lo_;
|
||||
}
|
||||
|
||||
void
|
||||
IAllocator_DArena::destruct_data(DArena & s)
|
||||
{
|
||||
s.~DArena();
|
||||
}
|
||||
void
|
||||
IAllocator_DArena::destruct_data(DArena & s)
|
||||
{
|
||||
s.~DArena();
|
||||
}
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue