Back to Basics: Class Layout - Stephen Dewhurst - CppCon 2020

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ส.ค. 2024
  • cppcon.org/
    github.com/Cpp...
    ---
    In C++, as in many other languages, classes are the key feature that supports data abstraction. A C++ class is essentially a C structure, but with added capabilities that support object-oriented programming as well as better type safety, resource management, and usability.
    Although some of these added capabilities require additional storage allocation or run-time support, most do not. Thus, the storage layout for a C++ class can be as simple as the layout for a C structure. Unfortunately, too many programmers imagine that classes incur space and speed penalties that simply aren’t there.
    This session offers a practical look “under the hood” to see how compilers typically implement the storage layout and member access for C++ classes. It also explains how compilers typically implement member function calls. You’ll come away with a better sense of what using classes actually costs in speed and space. You’ll gain insights that will help you with a variety of programming tasks, including debugging, performance tuning, and working with objects that have rigid layout requirements.
    ---
    Steve Dewhurst is the co-founder and president of Semantics Consulting, Inc. Steve is the author of numerous technical articles on C++ programming techniques and compiler design, is the author of the critically acclaimed books C++ Common Knowledge and C++ Gotchas, and is the co-author of Programming in C++. He is a frequent speaker at industry conferences, where his presentations are consistently among the most popular and highest rated. He is also a member of the advisory board for The C++ Source, was programming track chair for the Embedded Systems Conference (ESC), and was a visiting scientist at the Software Engineering Institute (SEI) at Carnegie Mellon University. Steve has mentored and consulted with C++ projects ranging in size from 1 to over 100 developers, in areas ranging from compiler design to embedded telecommunications to ecommerce to derivative securities trading. As a Member of Technical Staff in the UNIX Development Laboratory at AT&T Bell Laboratories, Steve worked with Bjarne Stroustrup, the designer and first implementer of C++, on the first public release of the language and cfront C++ compiler, then served as the lead designer and implementer of the first non-cfront C++ compiler. As a compiler architect at Glockenspiel, Ltd., he designed and implemented a second C++ compiler. Steve was a contributing editor for The C/C++ User's Journal, a principal lecturer at The C++ Seminar, has served as a principal on the ANSI/ISO C++ standardization committee, was the C++ training series adviser for Technology Exchange Company (Addison-Wesley), was a member of the editorial board of and columnist for C++ Report, co-founder and member of the editorial board of The C++ Journal, and a Visiting Professor of Computer Science at Jackson State University. He has also written C, COBOL, and Pascal compilers, was a principal on the ANSI/IEEE Pascal Standardization Committee, and a reviewer for ACM Computing Reviews. Semantics Consulting, Inc. is located in the small New England town of Carver, Massachusetts. Like all small New England towns, Carver has a tradition of citizen involvement, and over the years Steve has been astonished to find himself harvesting cranberries, coaching the high school wrestling team, and serving on the town water commission, finance committee, and website committee.
    ---
    Streamed & Edited by Digital Medium Ltd - events.digital-medium.co.uk
    events@digital-medium.co.uk
    *-----*
    Register Now For CppCon 2022: cppcon.org/reg...
    *-----*

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

  • @norikazuoshiro6324
    @norikazuoshiro6324 3 ปีที่แล้ว +22

    I learn something new and useful everytime i watch a cppcon video, especially Back to Basics series. Thank you, Mr Stephen Dewhurst for the great talk.

  • @georganatoly6646
    @georganatoly6646 3 ปีที่แล้ว +4

    hate to admit but I was completely ignorant to , turned out to be an exceptionally informative talk!

  • @lck5217
    @lck5217 3 ปีที่แล้ว +5

    ДОВЕРЯЙ НО ПРОВЕРЯЙ!
    GREAT TALK!

  • @YourCRTube
    @YourCRTube 3 ปีที่แล้ว +20

    Imagine a newcomer watching this thinking it's "the basics" 😁
    Good talk otherwise, though the second part has a strong overlap with last year talk about virtual classes

    • @shmekelfreckles8157
      @shmekelfreckles8157 3 หลายเดือนก่อน

      Do they actually have “the basics”?

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

    this is an extremly good talk. thanks Stephen!

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

    Proposed augmentation to the statemen that C++ is getting easier to write: it is getting easier to write more complex C++ cause I still don't understand most of it haha. After this presentation, I learned that I know even less about C++ than before. Great presentation! Thank you.

  • @martinelzen5127
    @martinelzen5127 3 ปีที่แล้ว +5

    This was a cool lecture, I'm glad I watched it and learned some things. The explanation of *why* the using-memcmp-across-data-members is a bad thing, could have been clearer, though. If memory serves the standard does *NOT* allow memory to be touched which hasn't been explicitly initialized, which means if any padding gets added anywhere, you've instantly gone to UB-land...

  • @rodion988
    @rodion988 3 ปีที่แล้ว +4

    Thank you Stephen for this lecture, very informative.

    • @CppCon
      @CppCon  3 ปีที่แล้ว

      Glad it was helpful!

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

    Learned a lot of new things. Very clearly explained. Thanks

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

    A lot of useful information. Thanks!

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

      Glad it was helpful! Thank you.

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

    After watching this I'm amazed upcasting and downcasting works at all...

  • @riderwang9770
    @riderwang9770 3 ปีที่แล้ว

    Stephen is always the best

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

    Enjoyed the virtual and vtbl discussions in this talk. I'm uncertain I would call it "basics" but more label it "essentials" for class layout. Just because inheritance and multiple inheritance doesn't seem basic at all.

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

    It is all also relative to c++1998, and I think people who worked with c++ for 3-4 years and read book on the subject. Still it is a nice talk to highlight possible problems, even they are pretty old. To learn layouts for compilers sometimes authors of compilers share technical docs.

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

    Great talk!

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

    What is object/type level protection mentioned @ 6:20 ?!

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

    Maybe the virtual table is not a good design right from the beginning. Multiple inheritance brings whole lot of mess.
    If we have some meta programming mechanism in c++, while allow us to copy functions into another class, replace and remove some of them, it should be easier. Then the mess is thrown to how a container stores multiple types, or at least pointers of different types while all the pointers are of the same size.

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

    I was despairing about having to memorize what constitutes a standard layout class. Deeply grateful for std::is_standard_layout. Does it always work?

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

    I guess embedded people are right not to trust C++ after all
    Great explanations however