@@ -125,7 +125,7 @@ class block_pool_resource : public block_resource_base<BlockSize, BlockPoolExpan
125
125
};
126
126
127
127
// / \brief Different increment levels match different chunk sizes.
128
- // / 512 means that 512 consecutive memory blocks are allocated at a time, and the block size is N .
128
+ // / 512 means that 512 consecutive memory blocks are allocated at a time.
129
129
template <std::size_t L>
130
130
constexpr std::size_t block_pool_expansion = 0 ;
131
131
@@ -134,20 +134,18 @@ template <> constexpr std::size_t block_pool_expansion<1> = 256;
134
134
template <> constexpr std::size_t block_pool_expansion<2 > = 128 ;
135
135
template <> constexpr std::size_t block_pool_expansion<3 > = 64 ;
136
136
137
- // / \brief Match the appropriate memory block resources according to the size of the specification.
138
- template <std::size_t N, std::size_t L = regular_level(N)>
139
- struct regular_resource {
140
- static auto *get () noexcept {
141
- using block_poll_resource_t = block_pool_resource<N, block_pool_expansion<L>>;
142
- return dynamic_cast <block_poll_resource_t *>(block_poll_resource_t::get ());
143
- }
144
- };
137
+ // / \brief Matches the appropriate memory block resource based on the specified type.
138
+ template <typename T, std::size_t N = regular_sizeof<T>(), std::size_t L = regular_level(N)>
139
+ auto *get_regular_resource () noexcept {
140
+ using block_poll_resource_t = block_pool_resource<N, block_pool_expansion<L>>;
141
+ return dynamic_cast <block_poll_resource_t *>(block_poll_resource_t::get ());
142
+ }
145
143
146
144
// / \brief Creates an object based on the specified type and parameters with block pool resource.
147
145
// / \note This function is thread-safe.
148
146
template <typename T, typename ... A>
149
147
T *new $(A &&... args) noexcept {
150
- auto *res = regular_resource<regular_sizeof<T>()>:: get ();
148
+ auto *res = get_regular_resource<T> ();
151
149
if (res == nullptr ) return nullptr ;
152
150
return ::LIBIMP::construct<T>(res->allocate (sizeof (T), alignof (T)), std::forward<A>(args)...);
153
151
}
@@ -159,7 +157,7 @@ template <typename T>
159
157
void delete $(T *p) noexcept {
160
158
if (p == nullptr ) return ;
161
159
::LIBIMP::destroy (p);
162
- auto *res = regular_resource<regular_sizeof<T>()>:: get ();
160
+ auto *res = get_regular_resource<T> ();
163
161
if (res == nullptr ) return ;
164
162
#if (LIBIMP_CC_MSVC > LIBIMP_CC_MSVC_2015)
165
163
res->deallocate (p, sizeof (T), alignof (T));
0 commit comments