Should I use smart pointers at all and forget about classic normal pointers?

I have been using C ++ for a long time and I know very well about caution when allocating and freeing memory, especially not forgetting to delete unused instances.

Now, I just recently used boost and with the problem I am facing, I am forced to use smart pointers (in particular, shared_ptr). So, if I am going to use shared_ptr for this problem, should I use smart pointers to my entire normal code base of pointers?

+5
source share
5 answers

. . - .

, ( ). , , .

+16

, . , ::boost::shared_ptr . , shared_ptr .

shared_ptr, ::std::auto_ptr , ++ 0x ::std::unique_ptr. , .

, . .

, , . , .

, , , . , C, , , free . , , realloc, ::std::vector - .

, , ( ::boost::shared_ptr ( ++ 0x ::std::shared_ptr)) .

+5

. Boost , . , , /, , . (, ) .

scoped_ptr , . , // , . , . , , - , - NULL if.

+1

, . new:

  • ?
  • ?
  • ?

, . " , , shared_pointer!"

: ?, , .

0

. , .

  • Smart pointers have overhead. On desktop applications this is usually not a concern, but depending on what you do, it may be.
  • Smart pointers will not work correctly if you have reference loops, i.e. A pointing to B and B pointing to A, or even something that points to itself.
-1
source

All Articles