Related to 10:32, a std::unique_ptr was chosen over a std::shared_ptr because the Person class will be the only point of access to m_impl? I'm exploring in general what are the trade-offs between shared vs unique.
Correct! Generally prefer unique over shared for both performance and safety -- unless you know that the data must be shared. For pImpl pattern, unique makes sense as you have suggested :)
This should be your next jeopardy quiz shhhh 🤫 (I confess I haven't finished you jeopardy video yet and wanted to wait so you may already have this in there)
Excellent video. Crisp and clear. I always had a concern that my company's legacy codes are exposing so much internal details to the customers. I am going to implement this approach.
Another great video. My general understanding of pointers is improving but I’m still uncomfortable with them. For instance, why did you have to use new to prevent the segmentation error?
Need to make sure something is allocated before you derefrence (i.e. access) any data that is being pointed to. This is something I put together to help folks with pointers: th-cam.com/video/2R5cjpi9Fzw/w-d-xo.html
great explanation. thx. but could you clarify one thing. how do you actually hide your implementation from customers? do you encrypt your cpp file, or do anything else? thx
Typically since the code is in the .cpp file the binary code is 'hidden' from customers. Folks may also obfuscate code and run a command like 'strip' to further obfuscate the generated code.
Both can be used together, pIMPL is useful for ABI stability and information hiding, and lazy initailization. RAII is one of the favorite features of C++ because it gives deterministic creation of objects, and ensures resources are closed when terminated or otherwise exceptions are thrown.
Information hiding is the big one. The other major one would be abi stability, as a pointer will always be 8 bytes on a 64-bit system. So if you make changes to the class, those happen in the implementation, and the class size does not change.
Incredible explanation, I was struggling to understand the benefits of this tecnique but your video clarified everything :D
Cheers -- I'm happy to hear that!
Wow, that's so nice explanation! Thanks!
Cheers!
Related to 10:32, a std::unique_ptr was chosen over a std::shared_ptr because the Person class will be the only point of access to m_impl? I'm exploring in general what are the trade-offs between shared vs unique.
This reminds me I need to rewatch th-cam.com/video/DHu0tv2qTYo/w-d-xo.html and the other related smart pointer videos.
Correct! Generally prefer unique over shared for both performance and safety -- unless you know that the data must be shared. For pImpl pattern, unique makes sense as you have suggested :)
This should be your next jeopardy quiz shhhh 🤫 (I confess I haven't finished you jeopardy video yet and wanted to wait so you may already have this in there)
@@damondouglas Not a bad idea. It will probably be worthwhile to have a few more review lessons along the way too :)
Excellent video. Crisp and clear. I always had a concern that my company's legacy codes are exposing so much internal details to the customers. I am going to implement this approach.
Cheers!
Great video. Wonderfully explained as always. Thank you.
Cheers, thank you Dhanush!
Your vidoes are very insightful. Please continue making more videos. Thank ypu
Thank you for the kind words Akash!
Great Explanation and thanks for covering this.
Cheers, thank you for the kind words!
Nice!! Thank you for pointing this video to me. This is helpful!
Cheers!
very well made video. thanks for uploading.
Thank you, my pleasure!
Fantastic Video thanks champ!
Cheers!
Another great video. My general understanding of pointers is improving but I’m still uncomfortable with them. For instance, why did you have to use new to prevent the segmentation error?
Need to make sure something is allocated before you derefrence (i.e. access) any data that is being pointed to. This is something I put together to help folks with pointers: th-cam.com/video/2R5cjpi9Fzw/w-d-xo.html
Very good, bro!
Thank you for the kind words!
hey mike! can you do a video on the type erasure idiom? Also where do you learn these idioms from? Thanks!
Will add that to the wish list! Idioms are learned over time through books, conference talks, and TH-cam! :)
great explanation.
thx.
but could you clarify one thing.
how do you actually hide your implementation from customers?
do you encrypt your cpp file, or do anything else? thx
Typically since the code is in the .cpp file the binary code is 'hidden' from customers. Folks may also obfuscate code and run a command like 'strip' to further obfuscate the generated code.
So people don't like RAII, but are fine with pimpl?!
Both can be used together, pIMPL is useful for ABI stability and information hiding, and lazy initailization. RAII is one of the favorite features of C++ because it gives deterministic creation of objects, and ensures resources are closed when terminated or otherwise exceptions are thrown.
What's the real benefit of this idiom other than just interface separation or hiding. I guess child classes of this class will have Impact.
Information hiding is the big one. The other major one would be abi stability, as a pointer will always be 8 bytes on a 64-bit system. So if you make changes to the class, those happen in the implementation, and the class size does not change.