wip
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#define MEMINFO_HPP
|
||||
|
||||
#include "util/log.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/resource.h>
|
||||
@@ -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: <not implemented on Windows>";
|
||||
#endif // _WIN32
|
||||
}
|
||||
} // namespace osrm::util
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -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<T *>(free_list.back());
|
||||
auto ptr = reinterpret_cast<T *>(free_list.back());
|
||||
free_list.pop_back();
|
||||
return ptr;
|
||||
}
|
||||
@@ -70,7 +70,8 @@ class MemoryPool
|
||||
template <typename T> 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<void *>(p));
|
||||
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
|
||||
free_lists_[free_list_index].push_back(reinterpret_cast<void *>(p));
|
||||
}
|
||||
|
||||
~MemoryPool()
|
||||
@@ -138,6 +139,8 @@ template <typename T> 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<MemoryPool> pool;
|
||||
};
|
||||
template <typename T, typename U>
|
||||
|
||||
Reference in New Issue
Block a user