Skip to content

Commit

Permalink
Add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Keita Iwabuchi committed Aug 16, 2024
1 parent 33ada83 commit 7aa5bf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/metall/container/fallback_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

namespace metall::container {

/// \brief A STL compatible allocator which fallbacks to a heap allocator (e.g.,
/// malloc()) if its constructor receives no argument to construct the stateful
/// allocator instance.
/// \brief A Metall STL compatible allocator which fallbacks to a heap allocator
/// (e.g., malloc()) if its constructor receives no argument to construct the
/// stateful allocator (Metall's normal STL compatible allocator) instance.
/// \tparam StatefulAllocator The stateful allocator type. It must not be
/// default constructible.
template <typename StatefulAllocator>
Expand Down Expand Up @@ -69,7 +69,7 @@ class fallback_allocator_adaptor {
fallback_allocator_adaptor(
fallback_allocator_adaptor<stateful_allocator_type2>
allocator_instance) noexcept
: m_stateful_allocator(allocator_instance.stateful_allocator()) {}
: m_stateful_allocator(allocator_instance.get_stateful_allocator()) {}

/// \brief Construct a new instance using an instance of any
/// stateful_allocator.
Expand Down Expand Up @@ -202,10 +202,10 @@ class fallback_allocator_adaptor {
// ---------- This class's unique public functions ---------- //

/// \brief Returns a reference to the stateful allocator.
stateful_allocator_type &stateful_allocator() { return m_stateful_allocator; }
stateful_allocator_type &get_stateful_allocator() { return m_stateful_allocator; }

/// \brief Returns a const reference to the stateful allocator.
const stateful_allocator_type &stateful_allocator() const {
const stateful_allocator_type &get_stateful_allocator() const {
return m_stateful_allocator;
}

Expand Down Expand Up @@ -259,7 +259,7 @@ inline bool operator==(
const fallback_allocator_adaptor<stateful_allocator_type> &rhd,
const fallback_allocator_adaptor<stateful_allocator_type> &lhd) {
// Return true if they point to the same manager kernel
return rhd.stateful_allocator() == lhd.stateful_allocator();
return rhd.get_stateful_allocator() == lhd.get_stateful_allocator();
}

template <typename stateful_allocator_type>
Expand Down
7 changes: 7 additions & 0 deletions test/container/fallback_allocator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ TEST(FallbackAllocatorAdaptorTest, Types) {
alloc);
GTEST_ASSERT_EQ(alloc, a2);
}

{
metall::manager manager(metall::create_only, dir_path(),
1UL << 27UL);
auto allocator = fb_alloc_type<int>(manager.get_allocator<int>());
ASSERT_EQ(allocator.get_stateful_allocator(), manager.get_allocator<int>());
}
}

TEST(FallbackAllocatorAdaptorTest, Availability) {
Expand Down

0 comments on commit 7aa5bf6

Please sign in to comment.