From 53fbcb883dc8ca208dc58a8cc168d0628fe2556f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 29 Jun 2023 09:25:56 -0700 Subject: 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 --- absl/strings/cord_analysis.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'absl/strings/cord_analysis.h') 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 @@ -30,6 +30,24 @@ namespace cord_internal { // memory could each be "charged" independently for the same shared memory. 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 -- cgit v1.2.3