Is it a good practice to always use smart pointers?

后端 未结 10 2039
眼角桃花
眼角桃花 2020-12-04 05:08

I find smart pointers to be a lot more comfortable than raw pointers. So is it a good idea to always use smart pointers? ( Please note that I am from Java b

10条回答
  •  情话喂你
    2020-12-04 05:45

    In many situations, I believe they are definitely the way to go (less messy cleanup code, reduced risk of leaks, etc.). However there is some very slight extra expense. If I were writing some code that had to be as fast as possible (say a tight loop that had to do some allocation and a free), I would probably not use a smart pointer in hopes of eking out a bit more speed. But I doubt that it would make any measurable difference in most situations.

提交回复
热议问题