Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method for minimum block size of a memory_pool #89

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions include/foonathan/memory/memory_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#ifndef FOONATHAN_MEMORY_MEMORY_POOL_HPP_INCLUDED
#define FOONATHAN_MEMORY_MEMORY_POOL_HPP_INCLUDED

// Inform that foonathan::memory::memory_pool::min_block_size API is available
#define FOONATHAN_MEMORY_MEMORY_POOL_HAS_MIN_BLOCK_SIZE

/// \file
/// Class \ref foonathan::memory::memory_pool and its \ref foonathan::memory::allocator_traits specialization.

Expand Down Expand Up @@ -55,6 +58,18 @@ namespace foonathan
static constexpr std::size_t min_node_size =
FOONATHAN_IMPL_DEFINED(free_list::min_element_size);

/// \returns The minimum block size required for certain number of \concept{concept_node,node}.
/// \requires \c node_size must be a valid \concept{concept_node,node size}
/// and \c number_of_nodes must be a non-zero value.
static constexpr std::size_t min_block_size(std::size_t node_size,
std::size_t number_of_nodes) noexcept
{
return detail::memory_block_stack::implementation_offset()
+ number_of_nodes
* (((node_size > min_node_size) ? node_size : min_node_size)
+ (detail::debug_fence_size ? 2 * detail::max_alignment : 0));
}

/// \effects Creates it by specifying the size each \concept{concept_node,node} will have,
/// the initial block size for the arena and other constructor arguments for the \concept{concept_blockallocator,BlockAllocator}.
/// If the \c node_size is less than the \c min_node_size, the \c min_node_size will be the actual node size.
Expand Down