MCPcopy Create free account
hub / github.com/attermann/microReticulum / test_map_allocator

Function test_map_allocator

test/test_allocator/test_allocator.cpp:42–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42void test_map_allocator() {
43
44 // CBA TODO Figure out how to selectively use PSRAM for Bytes and Packet objects.
45
46 // Trigger creation of both heap and psram pool before starting
47 RNS::Utilities::Memory::pool_init(RNS::Utilities::Memory::heap_pool_info);
48 RNS::Utilities::Memory::pool_init(RNS::Utilities::Memory::altheap_pool_info);
49 //RNS::Utilities::Memory::dump_heap_stats();
50 HEAD("Initial Stats:", RNS::LOG_TRACE);
51 RNS::Utilities::Memory::dump_basic_pool_stats();
52 //RNS::Utilities::Memory::dump_basic_allocator_stats();
53
54 {
55 //using TestMap = std::map<Bytes, TestObject, std::less<Bytes>, RNS::Utilities::Memory::ContainerAllocator<std::pair<const Bytes, TestObject>>>;
56 using TestMap = std::map<std::string, TestObject, std::less<std::string>, RNS::Utilities::Memory::ContainerAllocator<std::pair<const std::string, TestObject>>>;
57 //using TestAlloc = RNS::Utilities::Memory::ContainerAllocator<std::pair<const std::string, TestObject>>;
58 //using TestStringAlloc = RNS::Utilities::Memory::ContainerAllocator<char>;
59 //using TestMap = std::map<std::string, TestObject, std::less<std::string>, std::scoped_allocator_adaptor<TestAlloc, TestStringAlloc>>;
60
61 HEAD("Post-map Stats:", RNS::LOG_TRACE);
62 RNS::Utilities::Memory::dump_basic_pool_stats();
63 //RNS::Utilities::Memory::dump_basic_allocator_stats();
64
65 // CBA The following empty vector object is included in the memory allocated for std::map and uses psram
66 std::vector<std::string> vec;
67#ifdef VECTOR_EXTERNAL_CONTENT
68 // CBA The following vector entries use psram
69 vec.push_back("foo");
70 vec.push_back("bar");
71#endif
72
73 // CBA The following empty Bytes object is included in the memory allocated for std::map and uses psram
74 RNS::Bytes buf;
75#ifdef BYTES_EXTERNAL_CONTENT
76 // CBA The following Bytes content use psram
77 buf.assign("This is a Bytes buffer allocated OUTSIDE of TestObject");
78#endif
79
80 TestMap map;
81 map.insert({"two", {"two", vec, buf}});
82 map.insert({"one", {"one", vec, buf}});
83
84 HEAD("Post-insert Stats:", RNS::LOG_TRACE);
85 RNS::Utilities::Memory::dump_basic_pool_stats();
86 //RNS::Utilities::Memory::dump_basic_allocator_stats();
87
88 TEST_ASSERT_EQUAL(2, map.size());
89 for (const auto& [key, entry] : map) {
90 TRACEF("key: %s, entry: %s", key.c_str(), entry.toString().c_str());
91 }
92 }
93
94 HEAD("Post-free Stats:", RNS::LOG_TRACE);
95 RNS::Utilities::Memory::dump_basic_pool_stats();
96 //RNS::Utilities::Memory::dump_basic_allocator_stats();
97
98}
99

Callers

nothing calls this directly

Calls 4

assignMethod · 0.80
insertMethod · 0.80
sizeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected