A Journey Into Non-Virtual Polymorphism
Rud Merriam | A Journey into Non-Virtual Polymorphism 2 Who Doesn’t Recognize This?? 1990 Borland Turbo C++Cppcon 2023 | Rud Merriam | A Journey into Non-Virtual Polymorphism 3 Background ● Experience – Medium.com (https://medium.com/@rudmerriam)Cppcon 2023 | Rud Merriam | A Journey into Non-Virtual Polymorphism 4 Polymorphism ● Greek: “many forms” (Obligatory statement) ● The use of a single variableCppcon 2023 | Rud Merriam | A Journey into Non-Virtual Polymorphism 5 Polymorphic Variables ● Base class pointer to derived class – Virtual functions are not bad! ● Standard Template Library0 码力 | 43 页 | 536.84 KB | 5 月前3Optimizing Away Virtual Functions May Be Pointless
carePhoto by Tech Nick on unsplashSimple benchmark class Base { public: int concrete() const; virtual int virt() const; }; void benchmark(Base *b, size_t num_iterations) { auto start = Clock::now(); virt_duration = end-start;There are interesting technical details and surprising conclusions that virtual functions can be actually faster. Since CPU architectures are mentioned, I'd expect to see deep nt-vs-inheritance-vs-other- ways-performanceDoes it even matter?Conclusions ● The notion that “virtual functions are slower” is flat out wrong. ○ Which is not to say they are faster ○ Some of the suggested0 码力 | 20 页 | 1.19 MB | 5 月前3BehaviorTree.CPP: Task Planning for Robots and Virtual Agents
name, const NodeConfig& config) : SyncActionNode(name, config) {} // You must override this virtual function NodeStatus tick() override { std::cout << "Type: [ApproachEnemy]. Instance:" <<0 码力 | 59 页 | 7.97 MB | 5 月前3C++ Exceptions for Smaller Firmware
Memory/Heap Increases Binary Size Requires whole C++ STL Run Time Type Info (RTTI) Exception Tables Exception Code Nondeterministic Slow Binary Search Frame Unwinding Type Comparison (dynamic_cast) output_pin { public: virtual ~output_pin() = default; virtual void level(bool p_high) = 0; }; 2122 class output_pin { public: virtual ~output_pin() = default; virtual void level(bool p_high) not severe ‼ severe 🚨 28class output_pin { public: virtual ~output_pin() = default; virtual status level(bool p_high) = 0; virtual resultlevel() = 0; }; 29 std::expected 30 0 码力 | 237 页 | 6.74 MB | 5 月前3Relocation: Blazing Fast Save And Restore, Then Morel!
refer to relocatability as what it means talking about “Position Independent Code”, relocation tables for dynamically linked libraries, … • It is about the application of Data Orientation techniques use of pointers for objects to refer to each other: many problems • The use of inheritance and virtual overrides for runtime polymorphism: • Extra indirection, lots of allocations, cognitive load (lifetimes runtime polymorphism? • Programmers make the virtual tables • Zoo type-erasure already generates virtual tables • The handles have the accessor to the virtual table *INDEX* as a member • Each subtype0 码力 | 41 页 | 2.81 MB | 5 月前3Exceptional C++
EXCEPTION_WRITE_FAULT; // 0 = read; 1 = write; 8 = DEP ex.ExceptionInformation[1] = 0x01ED6F42; // WHAT: the virtual address of the inaccessible data ?2021 Victor Ciura | @ciura_victor - Exceptional C++ 29 NT_TIB operationType = aExRecord->ExceptionInformation[0]; // the second array element specifies the virtual address of the inaccessible data ULONG_PTR virtualAddress = aExRecord->ExceptionInformation[1]; aExInfo->ExceptionRecord->ExceptionInformation[0]; // the second array element specifies the virtual address of the inaccessible data ULONG_PTR virtualAddress = aExInfo->ExceptionRecord->ExceptionInformation[1];0 码力 | 113 页 | 24.39 MB | 5 月前3Neighborhoods Banding Together: Reasoning Globally about Programs
high-complexity algorithms. Describe neighborhood interactions coarsely in small tables. Global phase Collate the small tables into a big table of interactions. Validate the interactions with low-complexity Instantiation + 🤠 Calledint function_adapter( int x ) interface -> { // ... } int virtual_function_adapter( int x ) interface virtual -> { // ... } int member_function_adapter( int x ) interface type -> { // For indirect calls through pointers or references to functions For indirect calls through virtual dispatch For indirect calls through pointers to member functions🥳 😎 🧐 🤠Bounded Recursion0 码力 | 49 页 | 1.03 MB | 5 月前3Class Layout
discussing static data members. Type member (included nested classes) do not affect class layout. Non-virtual member functions have no effect on class layout. However, let’s have a few words about them… 9 8 9Class Layout Copyright © 2020 by Stephen C. Dewhurst and Daniel Saks 3 Non-Virtual Member Functions Non-virtual member functions do not occupy any space in the object and don’t affect data member C. Dewhurst and Daniel Saks Non-Member Equivalent The calling sequence for an n-argument non-virtual member function may be the same as that for an (n+1)-argument free function. Some platforms use0 码力 | 51 页 | 461.37 KB | 5 月前3Back To Basics Functions
and as member functions in classes. Within our discussion of functions in classes, we'll touch on virtual functions, static functions, and operator overloading. We'll circle back to where we began on these variables( ● Note: member variables sometimes also called either fields or attributes. 68Virtual Functions (or Virtual Member Functions) (1/3) ● Member Functions role become interesting when we start talking about inheritance. ● Member Functions can be ‘overridden’ in derived classes. ○ Observe the ‘virtual’ keyword on line ‘6’ signaling that the function may be overridden ○ Observe the ‘override’ keyword0 码力 | 123 页 | 7.26 MB | 5 月前3Tracy: A Profiler You Don't Want to Miss
delegate interface to call the virtual method (if only we could manipulate/later vtable entries… C-style (or COM-style) dispatch tables?) class Shape { public: virtual float area(); }; class Shape return calculate_area(); } protected: virtual float calculate_area(); }; 52 Tips & Tricks Instrumenting dynamic dispatch (e.g., virtual calls)53 Capture callstack on “terminal” zones for0 码力 | 85 页 | 6.51 MB | 5 月前3
共 189 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
相关搜索词
JourneyIntoNonVirtualPolymorphismOptimizingAwayFunctionsMayBePointlessBehaviorTreeCPPTaskPlanningforRobotsandAgentsC++ExceptionsSmallerFirmwareRelocationBlazingFastSaveAndRestoreThenMorelExceptionalNeighborhoodsBandingTogetherReasoningGloballyaboutProgramsClassLayoutBackToBasicsTracyProfilerYouDonWanttoMiss