LLVM API Documentation

Capacity.h
Go to the documentation of this file.
00001 //===--- Capacity.h - Generic computation of ADT memory use -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the capacity function that computes the amount of
00011 // memory used by an ADT.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_SUPPORT_CAPACITY_H
00016 #define LLVM_SUPPORT_CAPACITY_H
00017 
00018 #include <cstddef>
00019 
00020 namespace llvm {
00021 
00022 template <typename T>
00023 static inline size_t capacity_in_bytes(const T &x) {
00024   // This default definition of capacity should work for things like std::vector
00025   // and friends.  More specialized versions will work for others.
00026   return x.capacity() * sizeof(typename T::value_type);
00027 }
00028 
00029 } // end namespace llvm
00030 
00031 #endif
00032