llvm.org GIT mirror llvm / 18dceba
Add a generic 'capacity_in_bytes' function to allow inspection of memory usage of various data structures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136233 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 9 years ago
3 changed file(s) with 47 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
539539 ++Ptr;
540540 }
541541 };
542
543 template
544 static inline size_t
545 capacity_in_bytes(const DenseMap &X) {
546 return X.getMemorySize();
547 }
542548
543549 } // end namespace llvm
544550
7777 return BeginX == static_cast(&FirstEl);
7878 }
7979
80 /// grow_pod - This is an implementation of the grow() method which only works
81 /// on POD-like data types and is out of line to reduce code duplication.
82 void grow_pod(size_t MinSizeInBytes, size_t TSize);
83
84 public:
8085 /// size_in_bytes - This returns size()*sizeof(T).
8186 size_t size_in_bytes() const {
8287 return size_t((char*)EndX - (char*)BeginX);
8388 }
84
89
8590 /// capacity_in_bytes - This returns capacity()*sizeof(T).
8691 size_t capacity_in_bytes() const {
8792 return size_t((char*)CapacityX - (char*)BeginX);
8893 }
8994
90 /// grow_pod - This is an implementation of the grow() method which only works
91 /// on POD-like data types and is out of line to reduce code duplication.
92 void grow_pod(size_t MinSizeInBytes, size_t TSize);
93
94 public:
9595 bool empty() const { return BeginX == EndX; }
9696 };
9797
737737
738738 };
739739
740 template
741 static inline size_t capacity_in_bytes(const SmallVector &X) {
742 return X.capacity_in_bytes();
743 }
744
740745 } // End llvm namespace
741746
742747 namespace std {
0 //===--- Capacity.h - Generic computation of ADT memory use -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the capacity function that computes the amount of
10 // memory used by an ADT.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_CAPACITY_H
15 #define LLVM_SUPPORT_CAPACITY_H
16
17 namespace llvm {
18
19 template
20 static inline size_t capacity_in_bytes(const T &x) {
21 // This default definition of capacity should work for things like std::vector
22 // and friends. More specialized versions will work for others.
23 return x.capacity() * sizeof(typename T::value_type);
24 }
25
26 } // end namespace llvm
27
28 #endif
29