这是测试我的问题的代码。
#include <iostream>
#include <stack>
using namespace std;
int main(){
int num;
int Array[1];
stack<int> Stack;
cout << "Int size " << sizeof(num) <<endl; // Output: Int size 4
cout << "Array size " << sizeof(num) <<endl; // Output: Array size 4
cout << "Stack size " << sizeof(Stack) <<endl; // Output: Stack size 80
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我试图了解内存空间分配。通常 int 内存大小为 4 个字节。但是,当我初始化一个Stackint 数据类型时std::stack,Stack大小为 80 字节。
应该是4吗?为什么要std::stack占用 80 个字节?或者堆栈内部实际上是什么大小为 80 字节?