c++ - std::set(rb-tree) 和 std::unordered_set(hashtable) 占用多少堆栈内存?
问题描述
考虑到比较器、哈希器和分配器是无状态的,rbtree
and的结构hashtable
应该是:
template</*...*/>
struct RBTree {
Node* header;
size_t count;
[[no_unique_address]] KeyComparer keyComparer;
[[no_unique_address]] KeyExtracter keyOf;
[[no_unique_address]] NodeAllocator nodeAlloc;
};
template</*...*/>
struct HashTable {
size_t* buckets;
Node* items;
size_t capacity;
size_t count;
size_t usedBucketCount;
[[no_unique_address]] KeyHasher keyHasher;
[[no_unique_address]] KeyExtracter keyOf;
[[no_unique_address]] NodeAllocator nodeAlloc;
};
static_assert(sizeof(RBTree</*...*/>) == 16);
static_assert(sizeof(HashTable</*...*/> == 40));
但实际上:
constexpr auto sizeOf_set = sizeof(std::set<double>);
// MSVC (std:c++ latest) Debug: 24
// MSVC (std:c++ latest) Release: 16
// clang 10.0.0 (-std=c++20) -O0, -O3: 48
constexpr auto sizeOf_unorderedSet = sizeof(std::unordered_set<double>);
// MSVC (std:c++ latest) Debug: 80
// MSVC (std:c++ latest) Release: 64
// clang 10.0.0 (-std=c++20) -O0, -O3: 56
对于rbtree
,MSVC(发布)的结果符合我的期望。(但为什么 48 代表铿锵???)对于hashtable
,我完全糊涂了......
我想知道我是否错过了一些必要的东西......
解决方案
推荐阅读
- scala - 列表缓冲区scala的排序
- ios - UIMainScreen 不是函数错误 NativeScript iOS
- android - Firebase 数据库永久连接
- java - 关于 org.springframework.messaging.MessageHeaders.get() 的声纳
- haskell - 为什么这个简单的组合不起作用?
- css - 任何人都可以在css文件中提供一些关于“-webkit”的信息吗?
- python - Python中C类型整数的最大值和最小值
- javascript - 如何验证复杂对象
- oracle - 从视图调用过程/包
- malloc - 将 GLIBC malloc() M_MMAP_THRESHOLD 增加到 1GB 的影响