Quantcast
Viewing all articles
Browse latest Browse all 8

Answer by kroiz for How to implement efficient C++ runtime statistics

If you are on C++11 you could use std::atomic<>

#include <atomic>class GlobalStatistics {public:    static GlobalStatistics &get() {        static GlobalStatistics instance;        return instance;    }    void incrTotalBytesProcessed(unsigned int incrBy) {        totalBytesProcessed += incrBy;    }    long long getTotalBytesProcessed() const { return totalBytesProcessed; }private:    std::atomic_llong totalBytesProcessed;    GlobalStatistics() { }    GlobalStatistics(const GlobalStatistics &) = delete;    void operator=(const GlobalStatistics &) = delete;};

Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>