为什么要使用一个VS其他:`提振:: shared_array` VS`提高:: shared_ptr的&LT;的std ::矢量&GT;`? [英] Why use one vs the other: `boost::shared_array` VS `boost::shared_ptr<std::vector>`?
问题描述
因此要处理的内存大斑点无论是图像或类似的明显有很多的选择。
So to deal with large blobs of memory either for an image or similar there are clearly lots of options.
由于我的智能指针和RAII的粉丝,我想知道它是否更聪明的去用:
Since I'm a fan of smart pointers and RAII I'm wondering about whether it's smarter to go with :
- 在
的shared_ptr
到的std ::矢量
- a
shared_ptr
to astd::vector
或
- 去与
shared_array
指向一个动态分配的数组。
- to go with a
shared_array
pointing to a dynamically allocated array.
什么是概念,实用和性能选择一个VS其他的含义是什么?
What are the conceptual, practical, and performance implications of choosing one vs the other?
推荐答案
这是一样的对丙阵列比较的std ::向量。
It's the same as comparing std::vector vs. C array.
想想 shared_array
作为RAII数组c。你得到的仅仅是自动内存释放。有用的情况下,当你处理第三方code返回数组。
从理论上讲,它比快的std :: vector的一些边缘情况,但更灵活,更不安全。
Think about shared_array
as a RAII C array. What you get is just automatic memory deallocation. Useful in cases when you deal with 3rd-party code that returns arrays.
Theoretically it's faster than std::vector in some edge cases, but much less flexible and less secure.
的std ::向量可能是更好的选择。
std::vector is probably the better choice.
这篇关于为什么要使用一个VS其他:`提振:: shared_array` VS`提高:: shared_ptr的&LT;的std ::矢量&GT;`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!