Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. UPDATE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. UPDATE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. UPDATE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

added 2 characters in body
Source Link
Germán Diago

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. NOTEUPDATE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. NOTE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. UPDATE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

updated bullet point 3. Added note about mixing reference counts
Source Link
Germán Diago

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. NOTE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code.

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

For what I can see in OpenCV documentation, this is a reference-counted smart pointer, essentially, same as boost::shared_ptr. Even it uses atomic operations on the reference count.

I would make the choice based on portability and interoperability.

  1. Is your system going to be ported elsewhere and depends on OpenCV for sure but not on boost? Then, stick to OpenCV cv::Ptr if you can avoid boost and you get rid of the dependency.

  2. Does boost::shared_ptr plays nice with the rest of OpenCV? If you have something returning a cv::Ptr from OpenCV library, maybe it's better to stick to cv::Ptr in these cases, because the reference count will be handled incorrectly if you mix both kind of pointers and the resource could be destroyed prematurely.

  3. You're going to stick to boost wherever you port the project? Then, stick to boost::shared_ptr when you can do it, it's more standard, people know it and will immediately understand your code. NOTE: In C++11 you have std::shared_ptr, which amounts to no dependency if you can afford it, so you can use std::shared_ptr in this case and get rid of boost also.

Just as a side note, there is a technique to mix boost and std shared pointers that can keep the reference correctly around and could be useful for someone. See this question, it could be relevant also for mixing other kind of reference-counted pointers: Conversion from boost::shared_ptr to std::shared_ptr?

In my experience, when you port something, the fewer dependencies, the better, or there are certain platforms for which compiling can be a hell. So make your choice based on portability if it's a concern and interoperability of pointers with libraries.

Source Link
Germán Diago
Loading
default