smart pointer

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Paul Varcholik 3 years, 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #234

    sky
    Participant

    Would are your thought in using smart pointer? While I am learning with your book, should I try to use smart pointer? Will it a big effort? Is the benefit good enough for the required effort?

    #235

    Paul Varcholik
    Keymaster

    I think smart pointers are great. While I’ve only made superficial use of them in the book, I have an upcoming series of DirectX videos that make extensive use of smart pointers.

    I don’t believe the effort is terribly large. It’s mostly a matter of replacing pointer declarations and explicit use of “new”. And if you still need access to the underlying raw pointer, you can use the get() accessor.

    As to the benefits, there are several. You no longer have to explicitly delete your heap-allocated memory. This helps prevent memory leaks. Furthermore, your smart pointers still free their memory if a code block exits prematurely (e.g. an exception is fired).

    There are myriad resources on this topic, including this one from InformIT.

    Paul

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.