]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/memory_usage.h
add subtree-ish sources for 12.0.3
[ceph.git] / 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.
5
6 #pragma once
7
8 #include <unordered_map>
9
10 namespace rocksdb {
11
12 // Helper methods to estimate memroy usage by std containers.
13
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;
18 return sizeof(umap) +
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*);
23 }
24
25 } // namespace rocksdb