Why use one vs the other: `boost::shared_array` VS `boost::shared_ptr`?

后端 未结 2 853
长情又很酷
长情又很酷 2021-01-06 09:02

So to deal with large blobs of memory either for an image or similar there are clearly lots of options.

Since I\'m a fan of smart pointers and RAII I\'m wondering ab

2条回答
  •  臣服心动
    2021-01-06 09:40

    It's the same as comparing std::vector vs. C array.

    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::vector is probably the better choice.

提交回复
热议问题