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

Method TestMemoryPoolBookmark

util/memory/pool_ut.cpp:285–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283 }
284
285 void TestMemoryPoolBookmark() {
286 TCheckedAllocator alloc;
287
288 {
289 TMemoryPool pool(200U, TMemoryPool::TExpGrow::Instance(), &alloc);
290 ui64* someData = pool.Allocate<ui64>();
291 static const ui64 TESTING{0x123456789ABCDEF};
292 *someData = TESTING;
293
294 const auto ma = pool.MemoryAllocated();
295 const auto chunkOverhead = ma - sizeof(ui64);
296 const auto firstChunkTotal = pool.MemoryWaste() + ma;
297
298 // Allocate some memory in pool but not enough to need new chunks:
299 {
300 TMemoryPool::TBookmark bookmarkA(pool);
301 for (size_t i = 0U; i != 10; ++i) {
302 UNIT_ASSERT(pool.Allocate<ui64>());
303 }
304 }
305 UNIT_ASSERT_VALUES_EQUAL(pool.MemoryAllocated(), ma);
306 UNIT_ASSERT_VALUES_EQUAL(*someData, TESTING);
307
308 // Allocate some memory in pool enough to need a new single chunk:
309 {
310 TMemoryPool::TBookmark bookmarkB(pool);
311 for (size_t i = 0U; i != 50; ++i) {
312 UNIT_ASSERT(pool.Allocate<ui64>());
313 }
314 }
315 UNIT_ASSERT_VALUES_EQUAL(pool.MemoryAllocated(), firstChunkTotal + chunkOverhead); // The last (second) chunk is completely free
316 UNIT_ASSERT_VALUES_EQUAL(*someData, TESTING);
317 }
318
319 alloc.CheckAtEnd();
320 }
321};
322
323UNIT_TEST_SUITE_REGISTRATION(TMemPoolTest);

Callers

nothing calls this directly

Calls 4

InstanceFunction · 0.85
MemoryAllocatedMethod · 0.80
MemoryWasteMethod · 0.80
CheckAtEndMethod · 0.80

Tested by

no test coverage detected