std :: array vs数组性能 [英] std::array vs array performance

查看:90
本文介绍了std :: array vs数组性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想构建一个非常简单的数组,例如

If I want to build a very simple array like

int myArray[3] = {1,2,3};

我应该改用std::array吗?

std::array<int, 3> a = {{1, 2, 3}};

使用std :: array与普通方法相比有什么优点?表现更好吗?只是更易于复制/访问?

What are the advantages of using std::array over usual ones? Is it more performant ? Just easier to handle for copy/access ?

推荐答案

与通常的相比,使用std::array有什么优势?

它具有友好的值语义,因此可以按值传递给函数或从函数返回.其界面使查找大小以及与基于STL样式的基于迭代器的算法结合使用更加方便.

It has friendly value semantics, so that it can be passed to or returned from functions by value. Its interface makes it more convenient to find the size, and use with STL-style iterator-based algorithms.

表现更好吗?

Is it more performant ?

应该完全一样.根据定义,它是一个简单的聚合,其中包含数组作为其唯一成员.

It should be exactly the same. By definition, it's a simple aggregate containing an array as its only member.

复制/访问是否更容易处理?

Just easier to handle for copy/access ?

是的

这篇关于std :: array vs数组性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆