From a3b20d36c8f77791e96f8e4b63a4493caa2cb4d0 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 7 Dec 2015 22:48:43 +0100 Subject: [PATCH] Use uint32_t for indices. This allows us to save some memory and opens up more possibilities for future optimizations. And 4,294,967,295 should still be more than enough space for our lists of traces, strings etc. pp. --- accumulatedtracedata.h | 2 +- libheaptrack.cpp | 4 ++-- linereader.h | 1 - tracetree.h | 10 +++++----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/accumulatedtracedata.h b/accumulatedtracedata.h index 774cd04..5490a54 100644 --- a/accumulatedtracedata.h +++ b/accumulatedtracedata.h @@ -32,7 +32,7 @@ template struct Index { - uint64_t index = 0; + uint32_t index = 0; explicit operator bool() const { diff --git a/libheaptrack.cpp b/libheaptrack.cpp index 5f5bc69..c8365fd 100644 --- a/libheaptrack.cpp +++ b/libheaptrack.cpp @@ -307,7 +307,7 @@ public: return; } updateModuleCache(); - const size_t index = s_data->traceTree.index(trace, s_data->out); + const auto index = s_data->traceTree.index(trace, s_data->out); #ifdef DEBUG_MALLOC_PTRS auto it = s_data->known.find(ptr); @@ -315,7 +315,7 @@ public: s_data->known.insert(ptr); #endif - if (fprintf(s_data->out, "+ %zx %zx %" PRIxPTR "\n", size, index, reinterpret_cast(ptr)) < 0) { + if (fprintf(s_data->out, "+ %zx %x %" PRIxPTR "\n", size, index, reinterpret_cast(ptr)) < 0) { writeError(); return; } diff --git a/linereader.h b/linereader.h index dd18630..13ee161 100644 --- a/linereader.h +++ b/linereader.h @@ -98,7 +98,6 @@ public: return readHex(hex); } - // only for usage in heaptrack_interpret bool operator>>(uint32_t& hex) { return readHex(hex); diff --git a/tracetree.h b/tracetree.h index 61fbc0f..d139bc5 100644 --- a/tracetree.h +++ b/tracetree.h @@ -36,7 +36,7 @@ struct TraceEdge // index associated to the backtrace up to this instruction pointer // the evaluation process can then reverse-map the index to the parent ip // to rebuild the backtrace from the bottom-up - std::size_t index; + uint32_t index; // Unsorted list of children, assumed to be small std::vector children; }; @@ -61,9 +61,9 @@ public: * * Unknown instruction pointers will be printed to @p out. */ - std::size_t index(const Trace& trace, FILE* out) + uint32_t index(const Trace& trace, FILE* out) { - size_t index = 0; + uint32_t index = 0; TraceEdge* parent = &m_root; for (int i = trace.size() - 1; i >= 0; --i) { const auto ip = trace[i]; @@ -76,7 +76,7 @@ public: if (it == parent->children.end() || it->instructionPointer != ip) { index = m_index++; it = parent->children.insert(it, {ip, index, {}}); - fprintf(out, "t %" PRIxPTR " %zx\n", reinterpret_cast(ip), parent->index); + fprintf(out, "t %" PRIxPTR " %x\n", reinterpret_cast(ip), parent->index); } index = it->index; parent = &(*it); @@ -86,7 +86,7 @@ public: private: TraceEdge m_root = {0, 0, {}}; - std::size_t m_index = 1; + uint32_t m_index = 1; }; #endif // TRACETREE_H -- 2.7.4