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...
*-----*
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.
hate to admit but I was completely ignorant to , turned out to be an exceptionally informative talk!
ДОВЕРЯЙ НО ПРОВЕРЯЙ!
GREAT TALK!
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
Do they actually have “the basics”?
this is an extremly good talk. thanks Stephen!
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.
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...
Thank you Stephen for this lecture, very informative.
Glad it was helpful!
Learned a lot of new things. Very clearly explained. Thanks
A lot of useful information. Thanks!
Glad it was helpful! Thank you.
After watching this I'm amazed upcasting and downcasting works at all...
Stephen is always the best
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.
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.
Great talk!
What is object/type level protection mentioned @ 6:20 ?!
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.
I was despairing about having to memorize what constitutes a standard layout class. Deeply grateful for std::is_standard_layout. Does it always work?
I guess embedded people are right not to trust C++ after all
Great explanations however