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

Поделиться
HTML-код
  • Опубликовано: 5 фев 2025
  • 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...
    *-----*

Комментарии • 24

  • @norikazuoshiro6324
    @norikazuoshiro6324 4 года назад +23

    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!

  • @yjc149
    @yjc149 Год назад +1

    this is an extremly good talk. thanks Stephen!

  • @QuintinMassey
    @QuintinMassey 4 года назад +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.

  • @rodion988
    @rodion988 3 года назад +5

    Thank you Stephen for this lecture, very informative.

    • @CppCon
      @CppCon  3 года назад

      Glad it was helpful!

  • @lck5217
    @lck5217 4 года назад +5

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

  • @Radioguy00
    @Radioguy00 4 года назад +1

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

  • @martinelzen5127
    @martinelzen5127 4 года назад +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...

  • @xealit
    @xealit 3 месяца назад

    C++ is indeed terrific to program embedded systems. It just feels like you talk foreign language to those systems. But if you bend and shoehorn it with templates and meta-programming, it is indeed great.
    Is there a compiler directive to check that a class is standard layout type? I.e. something like override that checks a member does indeed override something. -- ok, use is_standard_layout_v and many static_asserts. Another example how C++ is just foreign to digital hardware.

  • @YourCRTube
    @YourCRTube 4 года назад +22

    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

  • @zzzXopHeTzzz
    @zzzXopHeTzzz 3 года назад +1

    A lot of useful information. Thanks!

    • @CppCon
      @CppCon  3 года назад

      Glad it was helpful! Thank you.

  • @poppmeow7586
    @poppmeow7586 3 месяца назад

    it's like going through the book object model within 1 hour. Lots of details to revisit and recap later.

  • @KX36
    @KX36 2 года назад

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

  • @QaytbayALAtheer
    @QaytbayALAtheer 3 года назад +2

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

  • @riderwang9770
    @riderwang9770 4 года назад

    Stephen is always the best

  • @peterevans6752
    @peterevans6752 3 года назад +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 3 года назад

    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 4 года назад +1

    Great talk!

  • @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?

  • @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.

  • @alek282
    @alek282 3 года назад +3

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