Rework SHOW_MEMORY
All checks were successful
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|0|0|0|0|:clap:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, passed: 931
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head This commit looks good
All checks were successful
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|0|0|0|0|:clap:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, passed: 931
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head This commit looks good
closes #10
This commit is contained in:
26
Internal.h
26
Internal.h
@@ -40,13 +40,39 @@ operator<=>(const std::span<const uint8_t> &lhs,
|
||||
|
||||
// GCOVR_EXCL_START
|
||||
|
||||
#if SHOW_MEMORY
|
||||
#ifdef __APPLE__
|
||||
#include <malloc/malloc.h>
|
||||
#endif
|
||||
inline int64_t mallocBytes = 0;
|
||||
inline int64_t peakMallocBytes = 0;
|
||||
#endif
|
||||
|
||||
// malloc that aborts on OOM and thus always returns a non-null pointer
|
||||
__attribute__((always_inline)) inline void *safe_malloc(size_t s) {
|
||||
#if SHOW_MEMORY
|
||||
mallocBytes += s;
|
||||
if (mallocBytes > peakMallocBytes) {
|
||||
peakMallocBytes = mallocBytes;
|
||||
}
|
||||
#endif
|
||||
if (void *p = malloc(s)) {
|
||||
return p;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
// There's nothing safer about this than free. Only called safe_free for
|
||||
// symmetry with safe_malloc.
|
||||
__attribute__((always_inline)) inline void safe_free(void *p) {
|
||||
#if SHOW_MEMORY
|
||||
#ifdef __APPLE__
|
||||
mallocBytes -= malloc_size(p);
|
||||
#endif
|
||||
#endif
|
||||
free(p);
|
||||
}
|
||||
|
||||
// ==================== BEGIN ARENA IMPL ====================
|
||||
|
||||
/// Group allocations with similar lifetimes to amortize the cost of malloc/free
|
||||
|
Reference in New Issue
Block a user