找出结构的内存消耗
finding out memory consumption of a structure
我试图弄清楚我的结构将消耗多少。请考虑以下代码
struct tNode{
short data;
tnode *left;
tnode *right;
tnode *student;
}
所以我知道 data
是2个字节,但是 *left
, *right
和 *student
呢,他们将消耗多少内存以及如何计算。
您正在寻找操作员的尺寸
返回类型的对象表示字节中的大小
示例用法:
#include <iostream>
class tnode;
struct tNode {
short data;
tnode *left;
tnode *right;
tnode *student;
};
int main()
{
std::cout << sizeof(tNode) << std::endl;
return 0;
}
在我的机器上输出:
32
相关文章:
- 如何在C++类内存结构中创建"spacer"?
- 添加静态constexpr成员是否会更改结构/类的内存映射
- 使用内存地址访问结构的属性值
- 为什么这个 std::queue/指向结构的指针列表直到 List.Size() == 0 才释放内存?
- 包含矢量指针的结构的内存释放问题
- 如何在cpp中删除(免费)多维结构内存?
- C++,您能否设计一种数据结构,将指针保存在连续内存中并且不会使它们失效?
- 公共/私有/受保护是否会更改内存中结构的排列?
- C++ 结构内部的unordered_map会导致内存泄漏问题吗?
- 基于浅树的数据结构的内存分配器,用于频繁分配和解除分配
- 从只读内存中读取结构
- 具有 STL 类 c++ 的结构的内存分配
- 相同的结构可以在C++中分配不同的内存大小吗?
- 我可以使用哪种数据结构来释放连续内存中的内存?
- 如果不初始化结构中的向量,它会自动为空还是具有随机内存位置的值?
- C++编译大型结构时内存使用过多
- 使用Hazelcast替换共享内存结构数据
- c++ WINAPI 共享内存结构数组
- 向量的<T>内存结构
- 使用C和Cpp跟踪内存结构