That namespace contains a set of common STL containers that are predefined
with the appropriate allocators.
-Thus for mempool "unittest_1" we have automatically available to us:
+Thus for mempool "osd" we have automatically available to us:
- mempool::unittest_1::map
- mempool::unittest_1::multimap
- mempool::unittest_1::set
- mempool::unittest_1::multiset
- mempool::unittest_1::list
- mempool::unittest_1::vector
- mempool::unittest_1::unordered_map
+ mempool::osd::map
+ mempool::osd::multimap
+ mempool::osd::set
+ mempool::osd::multiset
+ mempool::osd::list
+ mempool::osd::vector
+ mempool::osd::unordered_map
Putting objects in a mempool
Then, in an appropriate .cc file,
- MEMPOOL_DEFINE_OBJECT_FACTORY(Foo, foo, unittest_1);
+ MEMPOOL_DEFINE_OBJECT_FACTORY(Foo, foo, osd);
The second argument can generally be identical to the first, except
when the type contains a nested scope. For example, for
In order to use the STL containers, simply use the namespaced variant
of the container type. For example,
- mempool::unittest_1::map<int> myvec;
+ mempool::osd::map<int> myvec;
Introspection
-------------
f(buffer_data) \
f(osd) \
f(osdmap) \
- f(osdmap_mapping) \
- f(unittest_1) \
- f(unittest_2)
+ f(osdmap_mapping)
// give them integer ids
for (int i = 0; i < count; ++i) {
a.insert(make_pair(base+i,base+i));
b.insert(make_pair(base+i,base+i));
- check_usage(mempool::unittest_1::id);
+ check_usage(mempool::osd::id);
}
}
TEST(mempool, vector_context)
{
- check_usage(mempool::unittest_1::id);
- EXPECT_EQ(mempool::unittest_1::allocated_bytes(), 0u);
- EXPECT_EQ(mempool::unittest_1::allocated_items(), 0u);
+ check_usage(mempool::osd::id);
+ EXPECT_EQ(mempool::osd::allocated_bytes(), 0u);
+ EXPECT_EQ(mempool::osd::allocated_items(), 0u);
for (unsigned i = 0; i < 10; ++i) {
vector<int> a;
- mempool::unittest_1::vector<int> b,c;
+ mempool::osd::vector<int> b,c;
eq_elements(a,b);
do_push_back(a,b,i,i);
eq_elements(a,b);
- check_usage(mempool::unittest_1::id);
+ check_usage(mempool::osd::id);
mempool::stats_t total;
map<std::string,mempool::stats_t> by_type;
- mempool::get_pool(mempool::unittest_1::id).get_stats(&total, &by_type);
- EXPECT_GE(mempool::unittest_1::allocated_bytes(), i * 4u);
- EXPECT_GE(mempool::unittest_1::allocated_items(), i);
+ mempool::get_pool(mempool::osd::id).get_stats(&total, &by_type);
+ EXPECT_GE(mempool::osd::allocated_bytes(), i * 4u);
+ EXPECT_GE(mempool::osd::allocated_items(), i);
c.swap(b);
eq_elements(a,c);
- check_usage(mempool::unittest_1::id);
+ check_usage(mempool::osd::id);
a.clear();
b.clear();
c.clear();
{
for (unsigned i = 1; i < 10; ++i) {
list<int> a;
- mempool::unittest_1::list<int> b,c;
+ mempool::osd::list<int> b,c;
eq_elements(a,b);
do_push_back(a,b,i,i);
eq_elements(a,b);
mempool::stats_t total;
map<std::string,mempool::stats_t> by_type;
- mempool::get_pool(mempool::unittest_1::id).get_stats(&total, &by_type);
- EXPECT_GE(mempool::unittest_1::allocated_bytes(), i * 4u);
- EXPECT_EQ(mempool::unittest_1::allocated_items(), i);
+ mempool::get_pool(mempool::osd::id).get_stats(&total, &by_type);
+ EXPECT_GE(mempool::osd::allocated_bytes(), i * 4u);
+ EXPECT_EQ(mempool::osd::allocated_items(), i);
eq_elements(a,c);
- check_usage(mempool::unittest_1::id);
+ check_usage(mempool::osd::id);
}
}
{
for (int i = 0; i < 10; ++i) {
set<int> a;
- mempool::unittest_1::set<int> b;
+ mempool::osd::set<int> b;
do_insert(a,b,i,i);
eq_elements(a,b);
- check_usage(mempool::unittest_1::id);
+ check_usage(mempool::osd::id);
}
for (int i = 1; i < 10; ++i) {
set<int> a;
- mempool::unittest_1::set<int> b;
+ mempool::osd::set<int> b;
do_insert(a,b,i,0);
EXPECT_NE(a.find(i/2),a.end());
EXPECT_NE(b.find(i/2),b.end());
a.erase(a.find(i/2));
b.erase(b.find(i/2));
eq_elements(a,b);
- check_usage(mempool::unittest_1::id);
+ check_usage(mempool::osd::id);
}
}
return l.a < r.a;
}
};
-MEMPOOL_DEFINE_OBJECT_FACTORY(obj, obj, unittest_2);
+MEMPOOL_DEFINE_OBJECT_FACTORY(obj, obj, osdmap);
TEST(mempool, test_factory)
{
obj *o1 = new obj();
obj *o2 = new obj(10);
obj *o3 = new obj(20,30);
- check_usage(mempool::unittest_2::id);
+ check_usage(mempool::osdmap::id);
EXPECT_NE(o1,nullptr);
EXPECT_EQ(o1->a,1);
EXPECT_EQ(o1->b,1);
delete o1;
delete o2;
delete o3;
- check_usage(mempool::unittest_2::id);
+ check_usage(mempool::osdmap::id);
}
TEST(mempool, vector)
{
{
- mempool::unittest_1::vector<int> v;
+ mempool::osd::vector<int> v;
v.push_back(1);
v.push_back(2);
}
{
- mempool::unittest_2::vector<obj> v;
+ mempool::osdmap::vector<obj> v;
v.push_back(obj());
v.push_back(obj(1));
}
TEST(mempool, set)
{
- mempool::unittest_1::set<int> set_int;
+ mempool::osd::set<int> set_int;
set_int.insert(1);
set_int.insert(2);
- mempool::unittest_2::set<obj> set_obj;
+ mempool::osdmap::set<obj> set_obj;
set_obj.insert(obj());
set_obj.insert(obj(1));
set_obj.insert(obj(1, 2));
TEST(mempool, map)
{
{
- mempool::unittest_1::map<int,int> v;
+ mempool::osd::map<int,int> v;
v[1] = 2;
v[3] = 4;
}
{
- mempool::unittest_2::map<int,obj> v;
+ mempool::osdmap::map<int,obj> v;
v[1] = obj();
v[2] = obj(2);
v[3] = obj(2, 3);
TEST(mempool, list)
{
{
- mempool::unittest_1::list<int> v;
+ mempool::osd::list<int> v;
v.push_back(1);
v.push_back(2);
}
{
- mempool::unittest_2::list<obj> v;
+ mempool::osdmap::list<obj> v;
v.push_back(obj());
v.push_back(obj(1));
}
TEST(mempool, unordered_map)
{
- mempool::unittest_2::unordered_map<int,obj> h;
+ mempool::osdmap::unordered_map<int,obj> h;
h[1] = obj();
h[2] = obj(1);
}
TEST(mempool, string_test)
{
- mempool::unittest_2::string s;
+ mempool::osdmap::string s;
s.reserve(100);
- EXPECT_GE(mempool::unittest_2::allocated_items(), s.capacity() + 1u); // +1 for zero-byte termination :
+ EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u); // +1 for zero-byte termination :
for (size_t i = 0; i < 10; ++i) {
s += '1';
s.append(s);
- EXPECT_GE(mempool::unittest_2::allocated_items(), s.capacity() + 1u);
+ EXPECT_GE(mempool::osdmap::allocated_items(), s.capacity() + 1u);
}
}