xo-alloc2: + Allocator.alloc_range() with DArena input
This commit is contained in:
parent
3184b37460
commit
70ce4712e1
15 changed files with 182 additions and 68 deletions
|
|
@ -19,16 +19,10 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
assert(arena);
|
||||
|
||||
if (arena->config_.store_header_flag_ == false) {
|
||||
arena->capture_error(error::alloc_iterator_not_supported);
|
||||
AllocHeader * begin_hdr = begin_header(arena);
|
||||
|
||||
if (!begin_hdr)
|
||||
return DArenaIterator::invalid();
|
||||
}
|
||||
|
||||
byte * begin_byte = arena->lo_;
|
||||
AllocHeader * begin_hdr = (AllocHeader *)begin_byte;
|
||||
|
||||
log && log(xtag("begin_hdr", begin_hdr));
|
||||
|
||||
|
|
@ -41,20 +35,48 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
AllocHeader * end_hdr = end_header(arena);
|
||||
|
||||
if (!end_hdr)
|
||||
return DArenaIterator::invalid();
|
||||
|
||||
log && log(xtag("end_hdr", end_hdr));
|
||||
|
||||
return DArenaIterator(arena, end_hdr);
|
||||
}
|
||||
|
||||
AllocHeader *
|
||||
DArenaIterator::begin_header(const DArena * arena)
|
||||
{
|
||||
assert(arena);
|
||||
|
||||
if (arena->config_.store_header_flag_ == false) {
|
||||
arena->capture_error(error::alloc_iterator_not_supported);
|
||||
|
||||
return DArenaIterator::invalid();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
byte * begin_byte = arena->lo_;
|
||||
AllocHeader * begin_hdr = (AllocHeader *)begin_byte;
|
||||
|
||||
return begin_hdr;
|
||||
}
|
||||
|
||||
AllocHeader *
|
||||
DArenaIterator::end_header(const DArena * arena)
|
||||
{
|
||||
assert(arena);
|
||||
|
||||
if (arena->config_.store_header_flag_ == false) {
|
||||
arena->capture_error(error::alloc_iterator_not_supported);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
byte * end_byte = arena->free_;
|
||||
AllocHeader * end_hdr = (AllocHeader *)end_byte;
|
||||
|
||||
log && log(xtag("end_hdr", end_hdr));
|
||||
|
||||
return DArenaIterator(arena, end_hdr);
|
||||
return end_hdr;
|
||||
}
|
||||
|
||||
AllocInfo
|
||||
|
|
|
|||
|
|
@ -3,15 +3,20 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "AllocIterator.hpp"
|
||||
#include "arena/IAllocator_DArena.hpp"
|
||||
#include "arena/IAllocIterator_DArenaIterator.hpp" // for alloc_range
|
||||
#include "arena/DArenaIterator.hpp"
|
||||
#include "padding.hpp"
|
||||
#include "xo/indentlog/scope.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace xo {
|
||||
using xo::facet::with_facet;
|
||||
using std::size_t;
|
||||
using std::byte;
|
||||
|
||||
|
|
@ -65,6 +70,35 @@ namespace xo {
|
|||
return s.alloc_info(mem);
|
||||
}
|
||||
|
||||
void dummy(const DArena & s) {
|
||||
byte * begin_mem = nullptr;
|
||||
DArenaIterator * ix = new (begin_mem) DArenaIterator(&s, DArenaIterator::begin_header(&s));
|
||||
obj<AAllocIterator,DArenaIterator> ix_vt{ix};
|
||||
|
||||
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DArena::alloc_range(const DArena & s,
|
||||
DArena & ialloc) noexcept -> range_type
|
||||
{
|
||||
byte * begin_mem = IAllocator_DArena::alloc(ialloc,
|
||||
sizeof(DArenaIterator));
|
||||
byte * end_mem = IAllocator_DArena::alloc(ialloc,
|
||||
sizeof(DArenaIterator));
|
||||
|
||||
assert(begin_mem);
|
||||
assert(end_mem);
|
||||
|
||||
DArenaIterator * begin_ix = new (begin_mem) DArenaIterator(&s, DArenaIterator::begin_header(&s));
|
||||
DArenaIterator * end_ix = new ( end_mem) DArenaIterator(&s, DArenaIterator::end_header(&s));
|
||||
|
||||
obj<AAllocIterator> begin_obj = with_facet<AAllocIterator>::mkobj(begin_ix);
|
||||
obj<AAllocIterator> end_obj = with_facet<AAllocIterator>::mkobj( end_ix);
|
||||
|
||||
return std::make_pair(begin_obj, end_obj);
|
||||
}
|
||||
|
||||
bool
|
||||
IAllocator_DArena::expand(DArena & s, size_t target_z) noexcept
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,9 +6,14 @@
|
|||
**/
|
||||
|
||||
#include "gc/IAllocator_DX1Collector.hpp"
|
||||
#include "gc/IAllocIterator_DX1CollectorIterator.hpp"
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
#include "arena/IAllocator_DArena.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::facet::with_facet;
|
||||
using std::size_t;
|
||||
using std::byte;
|
||||
|
||||
namespace mm {
|
||||
using value_type = IAllocator_DX1Collector::value_type;
|
||||
|
|
@ -61,6 +66,29 @@ namespace xo {
|
|||
return d.last_error();
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::alloc_range(const DX1Collector & d,
|
||||
DArena & ialloc) noexcept -> range_type
|
||||
{
|
||||
byte * begin_mem = IAllocator_DArena::alloc(ialloc,
|
||||
sizeof(DX1CollectorIterator));
|
||||
byte * end_mem = IAllocator_DArena::alloc(ialloc,
|
||||
sizeof(DX1CollectorIterator));
|
||||
|
||||
assert(begin_mem);
|
||||
assert(end_mem);
|
||||
|
||||
DX1CollectorIterator * begin_ix
|
||||
= new (begin_mem) DX1CollectorIterator(d.begin());
|
||||
DX1CollectorIterator * end_ix
|
||||
= new ( end_mem) DX1CollectorIterator(d.end());
|
||||
|
||||
obj<AAllocIterator> begin_obj = with_facet<AAllocIterator>::mkobj(begin_ix);
|
||||
obj<AAllocIterator> end_obj = with_facet<AAllocIterator>::mkobj( end_ix);
|
||||
|
||||
return std::make_pair(begin_obj, end_obj);
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::alloc(DX1Collector & d, size_type z) noexcept -> value_type
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,12 +14,14 @@ namespace xo {
|
|||
{
|
||||
switch (x) {
|
||||
case comparison::invalid:
|
||||
return "?comparison";
|
||||
break;
|
||||
case comparison::comparable:
|
||||
return "cmp";
|
||||
case comparison::incomparable:
|
||||
return "!cmp";
|
||||
}
|
||||
|
||||
return "?comparison";
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue