diff options
author | Abseil Team <absl-team@google.com> | 2023-06-29 09:25:56 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-06-29 09:26:57 -0700 |
commit | 53fbcb883dc8ca208dc58a8cc168d0628fe2556f (patch) | |
tree | 7075fe3a70f796194137f08957e54a6086b4cf9e /absl/strings/cord_analysis.h | |
parent | bde85071e497254e954c27b1b81b442a441ad4b0 (diff) |
Introduce a kTotalMorePrecise accounting mode for Cord::EstimatedMemoryUsage(). This mode avoids double-counting blocks that a Cord references more than once; otherwise it is similar to the existing kTotal mode.
There's no change to the existing kTotal or kFairShare accounting modes.
PiperOrigin-RevId: 544378591
Change-Id: I7b4ae55cd93d631194e59a9cd0ff07f47611219e
Diffstat (limited to 'absl/strings/cord_analysis.h')
-rw-r--r-- | absl/strings/cord_analysis.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/absl/strings/cord_analysis.h b/absl/strings/cord_analysis.h index 7041ad1a..9b9527a5 100644 --- a/absl/strings/cord_analysis.h +++ b/absl/strings/cord_analysis.h @@ -31,6 +31,24 @@ namespace cord_internal { size_t GetEstimatedMemoryUsage(const CordRep* rep); // Returns the *approximate* number of bytes held in full or in part by this +// Cord for the distinct memory held by this cord. This is similar to +// `GetEstimatedMemoryUsage()`, except that if the cord has multiple references +// to the same memory, that memory is only counted once. +// +// For example: +// absl::Cord cord; +// cord.append(some_other_cord); +// cord.append(some_other_cord); +// // Calls GetEstimatedMemoryUsage() and counts `other_cord` twice: +// cord.EstimatedMemoryUsage(kTotal); +// // Calls GetMorePreciseMemoryUsage() and counts `other_cord` once: +// cord.EstimatedMemoryUsage(kTotalMorePrecise); +// +// This is more expensive than `GetEstimatedMemoryUsage()` as it requires +// deduplicating all memory references. +size_t GetMorePreciseMemoryUsage(const CordRep* rep); + +// Returns the *approximate* number of bytes held in full or in part by this // CordRep weighted by the sharing ratio of that data. For example, if some data // edge is shared by 4 different Cords, then each cord is attribute 1/4th of // the total memory usage as a 'fair share' of the total memory usage. |