• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Abseil Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABSL_STRINGS_CORD_ANALYSIS_H_
16 #define ABSL_STRINGS_CORD_ANALYSIS_H_
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "absl/base/config.h"
22 #include "absl/strings/internal/cord_internal.h"
23 
24 namespace absl {
25 ABSL_NAMESPACE_BEGIN
26 namespace cord_internal {
27 
28 // Returns the *approximate* number of bytes held in full or in part by this
29 // Cord (which may not remain the same between invocations). Cords that share
30 // memory could each be "charged" independently for the same shared memory.
31 size_t GetEstimatedMemoryUsage(const CordRep* rep);
32 
33 // Returns the *approximate* number of bytes held in full or in part by this
34 // Cord for the distinct memory held by this cord. This is similar to
35 // `GetEstimatedMemoryUsage()`, except that if the cord has multiple references
36 // to the same memory, that memory is only counted once.
37 //
38 // For example:
39 //   absl::Cord cord;
40 //   cord.append(some_other_cord);
41 //   cord.append(some_other_cord);
42 //    // Calls GetEstimatedMemoryUsage() and counts `other_cord` twice:
43 //   cord.EstimatedMemoryUsage(kTotal);
44 //    // Calls GetMorePreciseMemoryUsage() and counts `other_cord` once:
45 //   cord.EstimatedMemoryUsage(kTotalMorePrecise);
46 //
47 // This is more expensive than `GetEstimatedMemoryUsage()` as it requires
48 // deduplicating all memory references.
49 size_t GetMorePreciseMemoryUsage(const CordRep* rep);
50 
51 // Returns the *approximate* number of bytes held in full or in part by this
52 // CordRep weighted by the sharing ratio of that data. For example, if some data
53 // edge is shared by 4 different Cords, then each cord is attribute 1/4th of
54 // the total memory usage as a 'fair share' of the total memory usage.
55 size_t GetEstimatedFairShareMemoryUsage(const CordRep* rep);
56 
57 }  // namespace cord_internal
58 ABSL_NAMESPACE_END
59 }  // namespace absl
60 
61 
62 #endif  // ABSL_STRINGS_CORD_ANALYSIS_H_
63