]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/memory_usage.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
8 #include <unordered_map>
12 // Helper methods to estimate memroy usage by std containers.
14 template <class Key
, class Value
, class Hash
>
15 size_t ApproximateMemoryUsage(
16 const std::unordered_map
<Key
, Value
, Hash
>& umap
) {
17 typedef std::unordered_map
<Key
, Value
, Hash
> Map
;
19 // Size of all items plus a next pointer for each item.
20 (sizeof(typename
Map::value_type
) + sizeof(void*)) * umap
.size() +
21 // Size of hash buckets.
22 umap
.bucket_count() * sizeof(void*);
25 } // namespace rocksdb