diff --git a/include/gp/allocator/buddy.hpp b/include/gp/allocator/buddy.hpp index 5f6f6a1..8718a35 100644 --- a/include/gp/allocator/buddy.hpp +++ b/include/gp/allocator/buddy.hpp @@ -14,6 +14,14 @@ namespace gp{ + /** + * @brief An allocator that uses the buddy algorithm to divide the space into allocatable memory. + * + * This is not resilient to memory fragmentation, but the smallest memory unit should always be allocatable unless the memory is actually full. + * + * @tparam max_msb The log2 rounded up of the maximum space you expect to address in bytes + * @tparam align The smallest size of memory you expect the allocator to allocate + */ template class buddy : public allocator { struct twig { @@ -42,16 +50,29 @@ namespace gp{ gp::buffer data; const size_t max_depth; const size_t twig_explore_length; + + /** + * @brief The depth of the tree required to allocate + */ static constexpr size_t max_theoric_depth = max_msb - gp::math::msb(align); + + /** + * @brief The actual number of twigs to support the specified depth + */ static constexpr size_t required_twigs = (1 << (max_theoric_depth + 1)) - 1; + /** - * ((max allocatable size - min allocatable size) ** 2 - 1) / 4 twigs in a bundle + * @brief ((max allocatable size - min allocatable size) ** 2 - 1) / 4 twigs in a bundle **/ static constexpr size_t span_size = required_twigs / 4 + (required_twigs % 4 != 0); + + /** + * @brief The array of twigs (in bundles) + */ gp::array stack; /** - * This code has been manually hecked and will always return. + * This code has been manually checked and will always return. * If you find a case where it doesn't, please file an issue. **/ #pragma clang diagnostic push