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

Method TestMemPool

util/memory/pool_ut.cpp:91–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90private:
91 inline void TestMemPool() {
92 TCheckedAllocator alloc;
93
94 {
95 TMemoryPool pool(123, TMemoryPool::TExpGrow::Instance(), &alloc);
96
97 for (size_t i = 0; i < 1000; ++i) {
98 UNIT_ASSERT(pool.Allocate(i));
99 }
100 }
101
102 alloc.CheckAtEnd();
103
104 {
105 TMemoryPool pool(150, TMemoryPool::TExpGrow::Instance(), &alloc);
106
107 pool.Allocate(8);
108
109 size_t memavail = pool.Available();
110 size_t memwaste = pool.MemoryWaste();
111 size_t memalloc = pool.MemoryAllocated();
112
113 for (size_t i = 0; i < 1000; ++i) {
114 void* m = pool.Allocate(i);
115 UNIT_ASSERT(m);
116 memset(m, 0, i);
117 }
118
119 UNIT_ASSERT_VALUES_EQUAL(pool.ClearReturnUsedChunkCount(true), 11);
120
121 UNIT_ASSERT_VALUES_EQUAL(memalloc - 8, pool.MemoryAllocated());
122 UNIT_ASSERT_VALUES_EQUAL(memwaste + 8, pool.MemoryWaste());
123 UNIT_ASSERT_VALUES_EQUAL(memavail + 8, pool.Available());
124
125 for (size_t i = 0; i < 1000; ++i) {
126 void* m = pool.Allocate(i);
127 UNIT_ASSERT(m);
128 memset(m, 0, i);
129 }
130
131 UNIT_ASSERT_VALUES_EQUAL(pool.ClearReturnUsedChunkCount(false), 12);
132
133 UNIT_ASSERT_VALUES_EQUAL(0, pool.MemoryAllocated());
134 UNIT_ASSERT_VALUES_EQUAL(0, pool.MemoryWaste());
135 UNIT_ASSERT_VALUES_EQUAL(0, pool.Available());
136 }
137
138 alloc.CheckAtEnd();
139
140 struct TConstructorTest {
141 int ConstructorType;
142 TConstructorTest()
143 : ConstructorType(1)
144 {
145 }
146 TConstructorTest(int)
147 : ConstructorType(2)
148 {

Callers

nothing calls this directly

Calls 7

InstanceFunction · 0.85
CheckAtEndMethod · 0.80
MemoryWasteMethod · 0.80
MemoryAllocatedMethod · 0.80
AllocateMethod · 0.45
AvailableMethod · 0.45

Tested by

no test coverage detected