Use uint32_t for indices.
authorMilian Wolff <mail@milianw.de>
Mon, 7 Dec 2015 21:48:43 +0000 (22:48 +0100)
committerMilian Wolff <mail@milianw.de>
Mon, 7 Dec 2015 21:48:43 +0000 (22:48 +0100)
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
libheaptrack.cpp
linereader.h
tracetree.h

index 774cd04..5490a54 100644 (file)
@@ -32,7 +32,7 @@
 template<typename Base>
 struct Index
 {
-    uint64_t index = 0;
+    uint32_t index = 0;
 
     explicit operator bool() const
     {
index 5f5bc69..c8365fd 100644 (file)
@@ -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<uintptr_t>(ptr)) < 0) {
+        if (fprintf(s_data->out, "+ %zx %x %" PRIxPTR "\n", size, index, reinterpret_cast<uintptr_t>(ptr)) < 0) {
             writeError();
             return;
         }
index dd18630..13ee161 100644 (file)
@@ -98,7 +98,6 @@ public:
         return readHex(hex);
     }
 
-    // only for usage in heaptrack_interpret
     bool operator>>(uint32_t& hex)
     {
         return readHex(hex);
index 61fbc0f..d139bc5 100644 (file)
@@ -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<TraceEdge> 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<uintptr_t>(ip), parent->index);
+                fprintf(out, "t %" PRIxPTR " %x\n", reinterpret_cast<uintptr_t>(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