Classes Part 30 - pIMPL (pointer to implementation) - More Stable APIs| Modern Cpp Series Ep. 67

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ธ.ค. 2024

ความคิดเห็น • 36

  • @juanxpeke
    @juanxpeke 11 หลายเดือนก่อน +9

    Incredible explanation, I was struggling to understand the benefits of this tecnique but your video clarified everything :D

    • @MikeShah
      @MikeShah  11 หลายเดือนก่อน +1

      Cheers -- I'm happy to hear that!

  • @andk6893
    @andk6893 2 หลายเดือนก่อน +1

    Wow, that's so nice explanation! Thanks!

    • @MikeShah
      @MikeShah  2 หลายเดือนก่อน +1

      Cheers!

  • @damondouglas
    @damondouglas ปีที่แล้ว +2

    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.

    • @damondouglas
      @damondouglas ปีที่แล้ว

      This reminds me I need to rewatch th-cam.com/video/DHu0tv2qTYo/w-d-xo.html and the other related smart pointer videos.

    • @MikeShah
      @MikeShah  ปีที่แล้ว +1

      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 :)

    • @damondouglas
      @damondouglas ปีที่แล้ว +1

      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)

    • @MikeShah
      @MikeShah  ปีที่แล้ว +2

      @@damondouglas Not a bad idea. It will probably be worthwhile to have a few more review lessons along the way too :)

  • @sreerajc2328
    @sreerajc2328 ปีที่แล้ว +2

    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.

  • @dhanushs1802
    @dhanushs1802 2 ปีที่แล้ว +3

    Great video. Wonderfully explained as always. Thank you.

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว

      Cheers, thank you Dhanush!

  • @akashkhunt4191
    @akashkhunt4191 2 ปีที่แล้ว +3

    Your vidoes are very insightful. Please continue making more videos. Thank ypu

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว

      Thank you for the kind words Akash!

  • @Southpaw101
    @Southpaw101 2 ปีที่แล้ว +1

    Great Explanation and thanks for covering this.

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว

      Cheers, thank you for the kind words!

  • @k0185123
    @k0185123 10 หลายเดือนก่อน

    Nice!! Thank you for pointing this video to me. This is helpful!

    • @MikeShah
      @MikeShah  10 หลายเดือนก่อน

      Cheers!

  • @abhijittaware4360
    @abhijittaware4360 2 ปีที่แล้ว +2

    very well made video. thanks for uploading.

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว

      Thank you, my pleasure!

  • @ashwinkumargopivalliammal914
    @ashwinkumargopivalliammal914 2 ปีที่แล้ว +1

    Fantastic Video thanks champ!

  • @QWin-ir6yq
    @QWin-ir6yq 6 หลายเดือนก่อน +1

    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?

    • @MikeShah
      @MikeShah  6 หลายเดือนก่อน +2

      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

  • @MarcosCpp
    @MarcosCpp 2 ปีที่แล้ว +1

    Very good, bro!

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว +1

      Thank you for the kind words!

  • @grippysocked
    @grippysocked 2 ปีที่แล้ว +3

    hey mike! can you do a video on the type erasure idiom? Also where do you learn these idioms from? Thanks!

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว +4

      Will add that to the wish list! Idioms are learned over time through books, conference talks, and TH-cam! :)

  • @user-mu2du3np7d
    @user-mu2du3np7d ปีที่แล้ว

    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

    • @MikeShah
      @MikeShah  ปีที่แล้ว +1

      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.

  • @scullyy
    @scullyy 11 หลายเดือนก่อน +1

    So people don't like RAII, but are fine with pimpl?!

    • @MikeShah
      @MikeShah  11 หลายเดือนก่อน

      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.

  • @antonfernando8409
    @antonfernando8409 2 ปีที่แล้ว +1

    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.

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว

      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.