xo-alloc2: + Allocator.available() + unit test
This commit is contained in:
parent
5b96781801
commit
7bca67eafc
7 changed files with 40 additions and 12 deletions
|
|
@ -55,6 +55,8 @@ namespace xo {
|
|||
* for allocator @p d.
|
||||
**/
|
||||
virtual std::size_t committed(Copaque d) const = 0;
|
||||
/** unallocated (but committed) size in bytes for allocator @p d **/
|
||||
virtual std::size_t available(Copaque d) const = 0;
|
||||
/** true iff allocator @p d is responsible for memory at address @p p.
|
||||
**/
|
||||
virtual bool contains(Copaque d, const void * p) const = 0;
|
||||
|
|
|
|||
|
|
@ -26,14 +26,16 @@ namespace xo {
|
|||
**/
|
||||
struct IAllocator_Any : public AAllocator {
|
||||
//using Impl = IAllocator_ImplType<xo::facet::DVariantPlaceholder>;
|
||||
using size_type = std::size_t;
|
||||
|
||||
// from AAllocator
|
||||
int32_t _typeseq() const override { return s_typeseq; }
|
||||
|
||||
[[noreturn]] const std::string & name(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] std::size_t reserved(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] std::size_t size(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] std::size_t committed(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] size_type reserved(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] size_type size(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] size_type committed(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] size_type available(Copaque) const override { _fatal(); }
|
||||
[[noreturn]] bool contains(Copaque, const void *) const override { _fatal(); }
|
||||
|
||||
[[noreturn]] bool expand(Opaque, std::size_t) const override { _fatal(); }
|
||||
|
|
|
|||
|
|
@ -28,10 +28,13 @@ namespace xo {
|
|||
* RAllocator RAllocator.hpp
|
||||
*/
|
||||
struct IAllocator_DArena {
|
||||
using size_type = std::size_t;
|
||||
|
||||
static const std::string & name(const DArena &);
|
||||
static std::size_t reserved(const DArena &);
|
||||
static std::size_t size(const DArena &);
|
||||
static std::size_t committed(const DArena &);
|
||||
static size_type reserved(const DArena &);
|
||||
static size_type size(const DArena &);
|
||||
static size_type committed(const DArena &);
|
||||
static size_type available(const DArena &);
|
||||
static bool contains(const DArena &, const void * p);
|
||||
|
||||
/** expand committed space in arena @p d
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace xo {
|
|||
struct IAllocator_Xfer : public AAllocator {
|
||||
// parallel interface to AAllocator, with specific data type
|
||||
using Impl = IAllocator_DRepr;
|
||||
using size_type = std::size_t;
|
||||
|
||||
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
|
||||
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
|
||||
|
|
@ -27,15 +28,19 @@ namespace xo {
|
|||
const std::string & name(Copaque d) const override {
|
||||
return Impl::name(_dcast(d));
|
||||
}
|
||||
std::size_t reserved(Copaque d) const override {
|
||||
size_type reserved(Copaque d) const override {
|
||||
return Impl::reserved(_dcast(d));
|
||||
}
|
||||
std::size_t size(Copaque d) const override {
|
||||
size_type size(Copaque d) const override {
|
||||
return Impl::size(_dcast(d));
|
||||
}
|
||||
std::size_t committed(Copaque d) const override {
|
||||
size_type committed(Copaque d) const override {
|
||||
return Impl::committed(_dcast(d));
|
||||
}
|
||||
size_type available(Copaque d) const override {
|
||||
return I::available(_dcast(d));
|
||||
}
|
||||
|
||||
bool contains(Copaque d, const void * p) const override {
|
||||
return Impl::contains(_dcast(d), p);
|
||||
}
|
||||
|
|
@ -53,6 +58,10 @@ namespace xo {
|
|||
return Impl::destruct_data(*(DRepr*)d);
|
||||
}
|
||||
|
||||
private:
|
||||
using I = Impl;
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ namespace xo {
|
|||
size_type reserved() const { return O::iface()->reserved(O::data()); }
|
||||
size_type size() const { return O::iface()->size(O::data()); }
|
||||
size_type committed() const { return O::iface()->committed(O::data()); }
|
||||
size_type available() const { return O::iface()->available(O::data()); }
|
||||
bool contains(const void * p) const { return O::iface()->contains(O::data(), p); }
|
||||
bool expand(size_type z) { return O::iface()->expand(O::data(), z); }
|
||||
std::byte * alloc(size_type z) { return O::iface()->alloc(O::data(), z); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue