diff --git a/include/util/meminfo.hpp b/include/util/meminfo.hpp index 4c3e16f0b..9769b30d4 100644 --- a/include/util/meminfo.hpp +++ b/include/util/meminfo.hpp @@ -2,7 +2,6 @@ #define MEMINFO_HPP #include "util/log.hpp" -#include #ifndef _WIN32 #include @@ -11,31 +10,22 @@ namespace osrm::util { -inline size_t PeakRAMUsedInBytes() +inline void DumpMemoryStats() { #ifndef _WIN32 rusage usage; getrusage(RUSAGE_SELF, &usage); #ifdef __linux__ // Under linux, ru.maxrss is in kb - return usage.ru_maxrss * 1024; + util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss * 1024; #else // __linux__ // Under BSD systems (OSX), it's in bytes - return usage.ru_maxrss; + util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss; #endif // __linux__ -#else // _WIN32 - return 0; -#endif // _WIN32 -} - -inline void DumpMemoryStats() -{ -#ifndef _WIN32 - util::Log() << "RAM: peak bytes used: " << PeakRAMUsedInBytes(); #else // _WIN32 util::Log() << "RAM: peak bytes used: "; #endif // _WIN32 } } // namespace osrm::util -#endif +#endif \ No newline at end of file diff --git a/include/util/pool_allocator.hpp b/include/util/pool_allocator.hpp index 40cf6a3ea..35ed97075 100644 --- a/include/util/pool_allocator.hpp +++ b/include/util/pool_allocator.hpp @@ -62,7 +62,7 @@ class MemoryPool current_chunk_left_bytes_ -= block_size_in_bytes; current_chunk_ptr_ += block_size_in_bytes; } - auto ptr = static_cast(free_list.back()); + auto ptr = reinterpret_cast(free_list.back()); free_list.pop_back(); return ptr; } @@ -70,7 +70,8 @@ class MemoryPool template void deallocate(T *p, std::size_t n) noexcept { size_t free_list_index = get_next_power_of_two_exponent(n * sizeof(T)); - free_lists_[free_list_index].push_back(static_cast(p)); + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + free_lists_[free_list_index].push_back(reinterpret_cast(p)); } ~MemoryPool() @@ -138,6 +139,8 @@ template class PoolAllocator PoolAllocator &operator=(PoolAllocator &&) noexcept = default; private: + // using shared_ptr guarantees that memory pool won't be destroyed before all allocators using + // it (important if there are static instances of PoolAllocator) std::shared_ptr pool; }; template diff --git a/src/benchmarks/bench.cpp b/src/benchmarks/bench.cpp index d11277db3..23566824b 100644 --- a/src/benchmarks/bench.cpp +++ b/src/benchmarks/bench.cpp @@ -12,9 +12,9 @@ #include "osrm/coordinate.hpp" #include "osrm/engine_config.hpp" #include "osrm/json_container.hpp" + #include "osrm/osrm.hpp" #include "osrm/status.hpp" -#include "util/meminfo.hpp" #include @@ -655,13 +655,10 @@ try std::cerr << "Unknown benchmark: " << benchmarkToRun << std::endl; return EXIT_FAILURE; } - - std::cout << "Peak RAM: " << osrm::util::PeakRAMUsedInBytes() / (1024 * 1024) << "MB" - << std::endl; return EXIT_SUCCESS; } catch (const std::exception &e) { std::cerr << "Error: " << e.what() << std::endl; return EXIT_FAILURE; -} +} \ No newline at end of file