vector在堆上还是在栈上(等待自己慢慢领悟吧)

探索1:

ME:: L, vector变量是存放在堆上还是栈上的?网上说法不一,我也没有找到权威的表述
L: 堆、栈 和vector有啥关系?
L: 你把它放哪里,它就在哪里
ME: [分享]堆、栈的地址高低? 栈的增长方向? https://www.zhihu.com/question/36103513?sort=created
ME: 这个例子作者认为vector在堆上.
L: vector管理的内存在堆上
L: vector对象本身在栈上
L: 你把它放哪里,它就在哪里
ME: 那他的a3[1]还是在堆上吗
L: 在
ME: 那a3是在栈上吧?
L: 在栈上定义的对象,就在栈上
ME: OK

不知哪里来的说法:

无论你的定义是:
vector<int*> *p = new vector<int*>;
还是
vector<int*> p;
其元素都是在堆上进行分配。

别的论述:

https://www.it1352.com/454497.html

vector<Type> vect;

will allocate the vector, i.e. the header info, on the stack, but the elements on the free store ("heap").

vector<Type> *vect = new vector<Type>;

allocates everything on the free store.

vector<Type*> vect;

will allocate the vector on the stack and a bunch of pointers on the free store, but where these point is determined by how you use them (you could point element 0 to the free store and element 1 to the stack, say).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CodingLife99

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值