c++ 中vector 跟数组的区别

std::array is just a class version of the classic C array. That means its size is fixed at compile time and it will be allocated as a single chunk (e.g. taking space on the stack). The advantage it has is slightly better performance because there is no indirection between the object and the arrayed data.

数组是经典c数组的一个类版本。这意味着它的大小是在编译的时候固定的,并且被分配到到一整块(如栈中)中。它的优势是性能比vector要好,这是因为在object和数组数据之间没有任何直接的联系。

std::vector is a small class containing pointers into the heap. (So when you allocate astd::vector, it always calls new.) They are slightly slower to access because those pointers have to be chased to get to the arrayed data... But in exchange for that, they can be resized and they only take a trivial amount of stack space no matter how large they are.

vector 在堆中一个包含指针的小类。所以当分配一个vector时,将会调用new。这很明显的是很难接入,因为必须追踪这些指针,以得到数组的数据。但是,它可以重定义大小,并且无论vector多大,它仅仅占用对中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值