
vector在堆上还是在栈上(等待自己慢慢领悟吧)
发布日期:2021-05-09 00:20:28
浏览次数:20
分类:博客文章
本文共 859 字,大约阅读时间需要 2 分钟。
探索1:
ME:: L, vector变量是存放在堆上还是栈上的?网上说法不一,我也没有找到权威的表述
L: 堆、栈 和vector有啥关系?L: 你把它放哪里,它就在哪里ME: [分享]堆、栈的地址高低? 栈的增长方向? https://www.zhihu.com/question/36103513?sort=createdME: 这个例子作者认为vector在堆上.L: vector管理的内存在堆上L: vector对象本身在栈上L: 你把它放哪里,它就在哪里ME: 那他的a3[1]还是在堆上吗L: 在ME: 那a3是在栈上吧?L: 在栈上定义的对象,就在栈上ME: OK
不知哪里来的说法:
无论你的定义是:
vector<int*> *p = new vector<int*>;还是vector<int*> p;其元素都是在堆上进行分配。
别的论述:
vectorvect;
will allocate the vector, i.e. the header info, on the stack, but the elements on the free store ("heap").
vector*vect = new vector ;
allocates everything on the free store.
vectorvect;
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).
发表评论
最新留言
不错!
[***.144.177.141]2025年04月26日 23时02分20秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
常用元素操作的方法
2019-03-24
命名实体识别数据预处理
2019-03-25
分布式是登录机制是如何实现的。
2019-03-25
零基础学习 Vue3 教程 2021 年最新教程 免费视频教程(4 个视频)
2019-03-25
解决 matplotlib 中文显示乱码的问题
2023-01-23
解决打开 json 文件中文乱码的问题
2023-01-23
计算机网络基础:DHCP服务的部署
2023-01-23
计算机网络基础:DNS 部署与安全
2023-01-23
计算机网络基础:NAT 网络地址转换
2023-01-23
计算机网络基础:PKI(公钥基础设施)
2023-01-23
计算机网络基础:VLAN(虚拟局域网)
2023-01-23
计算机网络基础:文件共享服务器(注册表更改)
2023-01-23
计算机网络基础:用户和组管理
2023-01-23
计算机网络基础:简单渗透
2023-01-23
计算机网络模型-TCP/IP协议簇
2023-01-23
基于Arduino的ESP32-S3 + OLED(4pin)的文字取模
2023-01-23
基于Arduino的ESP32-S3 +光敏传感器(4pin)
2023-01-23
基于Arduino的ESP32-S3 + 1.3寸OLED(4pin)
2023-01-23