xo-arena: annex padding from xo-alloc2

This commit is contained in:
Roland Conybeare 2026-01-06 00:08:50 -05:00
commit 49ee32cb30
3 changed files with 4 additions and 66 deletions

View file

@ -1,60 +0,0 @@
/** @file padding.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include <memory>
#include <cstdint>
namespace xo {
namespace mm {
struct padding {
/** word size for alignment**/
static constexpr std::size_t c_alloc_alignment = sizeof(std::uintptr_t);
static inline std::size_t is_aligned(std::size_t n,
std::size_t align = c_alloc_alignment) {
return n % align == 0;
}
/** how much to add to @p z to get a multiple of
* @ref c_alloc_alignment
**/
static inline std::size_t alloc_padding(std::size_t z,
std::size_t align = c_alloc_alignment)
{
/* round up to multiple of c_bpw, but map 0 -> 0
* (table assuming c_bpw==8)
*
* z%c_bpw dz
* ------------
* 0 0
* 1 7
* 2 6
* .. ..
* 7 1
*/
std::size_t dz = (align - (z % align)) % align;
return dz;
}
/** @p z rounded up to an exact multiple
* of @ref c_alloc_alignment
**/
static inline
std::size_t with_padding(std::size_t z,
std::size_t align = c_alloc_alignment)
{
return z + alloc_padding(z, align);
}
};
} /*namespace mm*/
} /*namespace xo*/
/* end padding.hpp */

View file

@ -6,9 +6,9 @@
#include "alloc/AAllocator.hpp"
#include "arena/DArena.hpp"
#include "arena/DArenaIterator.hpp"
#include "xo/alloc2/padding.hpp"
#include "xo/indentlog/scope.hpp"
#include "xo/indentlog/print/tag.hpp"
#include <xo/arena/padding.hpp>
#include <xo/indentlog/scope.hpp>
#include <xo/indentlog/print/tag.hpp>
#include <cassert>
#include <sys/mman.h> // for ::munmap()
#include <unistd.h> // for ::getpagesize()

View file

@ -5,11 +5,9 @@
#include "xo/alloc2/Allocator.hpp"
#include "xo/alloc2/alloc/IAllocator_Xfer.hpp"
//#include "xo/alloc2/DArena.hpp"
#include "xo/alloc2/arena/IAllocator_DArena.hpp"
//#include "xo/alloc2/alloc/RAllocator.hpp"
#include "xo/alloc2/print.hpp"
#include "xo/alloc2/padding.hpp"
#include "xo/arena/padding.hpp"
#include <xo/facet/obj.hpp>
#include <xo/indentlog/scope.hpp>
#include <catch2/catch.hpp>