找出结构的内存消耗

finding out memory consumption of a structure

本文关键字:内存 结构      更新时间:2023-10-16

我试图弄清楚我的结构将消耗多少。请考虑以下代码

   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