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多大,它仅仅占用对中