MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / cpp_allocator_test

Function cpp_allocator_test

deps/memkind/src/examples/pmem_cpp_allocator.cpp:52–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50#endif
51
52void cpp_allocator_test(const char *pmem_directory)
53{
54 std::cout << "TEST SCOPE: HELLO" << std::endl;
55
56 size_t pmem_max_size = 1024*1024*1024;
57
58#ifdef STL_VECTOR_TEST
59 {
60 std::cout << "VECTOR OPEN" << std::endl;
61 pmem::allocator<int> alc{ pmem_directory, pmem_max_size };
62 std::vector<int, pmem::allocator<int>> vector{ alc };
63
64 for (int i = 0; i < 20; ++i) {
65 vector.push_back(0xDEAD + i);
66 assert(vector.back() == 0xDEAD + i);
67 }
68
69 std::cout << "VECTOR CLOSE" << std::endl;
70 }
71#endif
72
73#ifdef STL_LIST_TEST
74 {
75 std::cout << "LIST OPEN" << std::endl;
76 pmem::allocator<int> alc{ pmem_directory, pmem_max_size };
77 std::list<int, pmem::allocator<int>> list{ alc };
78
79 const int nx2 = 4;
80 for (int i = 0; i < nx2; ++i) {
81 list.emplace_back(0xBEAC011 + i);
82 assert(list.back() == 0xBEAC011 + i);
83 }
84
85 for (int i = 0; i < nx2; ++i) {
86 list.pop_back();
87 }
88
89 std::cout << "LIST CLOSE" << std::endl;
90 }
91#endif
92
93#ifdef STL_VEC_STRING_TEST
94 {
95 std::cout << "STRINGED VECTOR OPEN" << std::endl;
96 typedef pmem::allocator<char> str_alloc_t;
97 typedef std::basic_string<char, std::char_traits<char>, str_alloc_t>
98 pmem_string;
99 typedef pmem::allocator<pmem_string> vec_alloc_t;
100
101 vec_alloc_t vec_alloc{ pmem_directory, pmem_max_size };
102 str_alloc_t str_alloc{ pmem_directory, pmem_max_size };
103
104 std::vector<pmem_string, std::scoped_allocator_adaptor<vec_alloc_t> >
105 vec{ std::scoped_allocator_adaptor<vec_alloc_t>(vec_alloc) };
106
107 pmem_string arg{ "Very very loooong striiiing", str_alloc };
108
109 vec.push_back(arg);

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected