MCPcopy Create free account
hub / github.com/catboost/catboost / TestRoundUpToNextPowerOfTwoOption

Method TestRoundUpToNextPowerOfTwoOption

util/memory/pool_ut.cpp:244–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242 }
243
244 void TestRoundUpToNextPowerOfTwoOption() {
245 const size_t MEMORY_POOL_BLOCK_SIZE = (1024 - 16) * 4096 - 16 - 16 - 32;
246
247 class TFixedBlockSizeMemoryPoolPolicy final: public TMemoryPool::IGrowPolicy {
248 public:
249 size_t Next(size_t /*prev*/) const noexcept override {
250 return MEMORY_POOL_BLOCK_SIZE;
251 }
252 };
253 TFixedBlockSizeMemoryPoolPolicy allocationPolicy;
254
255 class TTestAllocator final: public TDefaultAllocator {
256 public:
257 TBlock Allocate(size_t len) override {
258 Size_ += len;
259 return TDefaultAllocator::Allocate(len);
260 }
261
262 size_t GetSize() const {
263 return Size_;
264 }
265
266 private:
267 size_t Size_ = 0;
268 };
269
270 TTestAllocator allocator;
271
272 TMemoryPool::TOptions options;
273 options.RoundUpToNextPowerOfTwo = false;
274
275 constexpr size_t EXPECTED_ALLOCATION_SIZE = MEMORY_POOL_BLOCK_SIZE + 32;
276 TMemoryPool pool(MEMORY_POOL_BLOCK_SIZE, &allocationPolicy, &allocator, options);
277
278 pool.Allocate(MEMORY_POOL_BLOCK_SIZE);
279 UNIT_ASSERT_VALUES_EQUAL(EXPECTED_ALLOCATION_SIZE, allocator.GetSize());
280
281 pool.Allocate(1);
282 UNIT_ASSERT_VALUES_EQUAL(2 * EXPECTED_ALLOCATION_SIZE, allocator.GetSize());
283 }
284
285 void TestMemoryPoolBookmark() {
286 TCheckedAllocator alloc;

Callers

nothing calls this directly

Calls 2

AllocateMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected