diff --git a/include/libpmr/new.h b/include/libpmr/new.h index a7bbdab..c160a51 100644 --- a/include/libpmr/new.h +++ b/include/libpmr/new.h @@ -125,7 +125,7 @@ public: }; /// \brief Different increment levels match different chunk sizes. -/// 512 means that 512 consecutive memory blocks are allocated at a time, and the block size is N. +/// 512 means that 512 consecutive memory blocks are allocated at a time. template constexpr std::size_t block_pool_expansion = 0; @@ -134,20 +134,18 @@ template <> constexpr std::size_t block_pool_expansion<1> = 256; template <> constexpr std::size_t block_pool_expansion<2> = 128; template <> constexpr std::size_t block_pool_expansion<3> = 64; -/// \brief Match the appropriate memory block resources according to the size of the specification. -template -struct regular_resource { - static auto *get() noexcept { - using block_poll_resource_t = block_pool_resource>; - return dynamic_cast(block_poll_resource_t::get()); - } -}; +/// \brief Matches the appropriate memory block resource based on the specified type. +template (), std::size_t L = regular_level(N)> +auto *get_regular_resource() noexcept { + using block_poll_resource_t = block_pool_resource>; + return dynamic_cast(block_poll_resource_t::get()); +} /// \brief Creates an object based on the specified type and parameters with block pool resource. /// \note This function is thread-safe. template T *new$(A &&... args) noexcept { - auto *res = regular_resource()>::get(); + auto *res = get_regular_resource(); if (res == nullptr) return nullptr; return ::LIBIMP::construct(res->allocate(sizeof(T), alignof(T)), std::forward(args)...); } @@ -159,7 +157,7 @@ template void delete$(T *p) noexcept { if (p == nullptr) return; ::LIBIMP::destroy(p); - auto *res = regular_resource()>::get(); + auto *res = get_regular_resource(); if (res == nullptr) return; #if (LIBIMP_CC_MSVC > LIBIMP_CC_MSVC_2015) res->deallocate(p, sizeof(T), alignof(T));