1 #include "allocator.h" 2 3 #if !defined(TESTMODE) 4 5 #define ALLOC_POOL(BYTES,NB) \ 6 MemoryPool<POOL_BLOCK_##BYTES,user_allocator_aligned_malloc> vecPool_##BYTES(NB); 7 8 #if defined(POOL_ALLOCATOR) 9 #include "allocation/all.cpp" 10 #endif 11 12 std::map<int, int> current_stats; 13 std::map<int, int> max_stats; 14 std::map<void*, std::size_t> current_dyn_stats; 15 16 #endif 17 print_map(std::string comment)18void print_map(std::string comment) 19 { 20 21 std::cout << comment << "\r\n"; 22 #if !defined(POOL_ALLOCATOR) && !defined(TESTMODE) 23 std::size_t total_static=0; 24 std::size_t total_dynamic=0; 25 26 for (const auto v : max_stats) 27 { 28 // Only count allocations with size known at build time 29 if (v.first > 0) 30 { 31 std::cout << "ALLOC_POOL(" << v.first << "," << v.second << "); \r\n"; 32 total_static += v.first * v.second; 33 } 34 } 35 36 for (const auto v : max_stats) 37 { 38 // Only count allocations with size known at build time 39 if (v.first > 0) 40 { 41 std::cout << "POOL(" << v.first << "); \r\n"; 42 } 43 } 44 45 std::cout << "\r\n"; 46 47 std::cout << "Total static bytes: " << total_static << std::hex << " (0x" << total_static << ")\r\n"; 48 49 total_dynamic = 0; 50 std::cout << "\r\nDynamic allocations\r\n"; 51 for (const auto v : max_stats) 52 { 53 // Only count allocations with size known at build time 54 if (v.first < 0) 55 { 56 // Count is meaningless for dynamic allocation 57 // since we can track the destroy (destroy has no length 58 // argument contrary to allocate and so can only get 59 // the length from the static value). 60 std::cout << std::dec << -v.first << " : " << v.second << "\r\n"; 61 total_dynamic += (-v.first) * v.second; 62 } 63 } 64 std::cout << "Total dynamic bytes: " << total_dynamic << std::hex << " (0x" << total_dynamic << ")\r\n"; 65 std::cout << "Total bytes: " << (total_static+total_dynamic) << std::hex << " (0x" << (total_static+total_dynamic) << ")\r\n"; 66 67 68 #endif 69 } 70 71 #if !defined(TESTMODE) 72 reset_current_stats()73void reset_current_stats() 74 { 75 #if !defined(POOL_ALLOCATOR) 76 for (auto v : current_stats) 77 { 78 v.second = 0; 79 } 80 #endif 81 } 82 check_current_stats()83void check_current_stats() 84 { 85 #if !defined(POOL_ALLOCATOR) 86 for (const auto v : current_stats) 87 { 88 if (v.second > 0) 89 { 90 if (v.first>0) 91 { 92 std::cout << "Error memory pool " << v.first << " not empty = " << v.second << "\r\n"; 93 } 94 else 95 { 96 std::cout << "Error dynamic alloc " << -v.first << " not empty = " << v.second << "\r\n"; 97 } 98 } 99 } 100 101 reset_current_stats(); 102 #endif 103 } 104 105 #endif 106