A Journey Into Non-Virtual PolymorphismRud 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 | 6 月前3
Optimizing Away Virtual Functions May Be PointlesscarePhoto 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 | 6 月前3
BehaviorTree.CPP: Task Planning for Robots and Virtual Agentsname, 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 | 6 月前3
Express Your Expectations: A Fast, Compliant JSON Pull Parser for Writing Robust Applications@foonathan Express your expectations CppCon 2023-10-03 11JSON DOM parser Jonathan Müller — @foonathan Express your expectations CppCon 2023-10-03 12JSON DOM parser Idea: Represent a JSON value in C++. auto p 2023-10-03 16Problems with JSON DOM parsers json_value is stringly typed, Jonathan Müller — @foonathan Express your expectations CppCon 2023-10-03 17Problems with JSON DOM parsers json_value is stringly allocation, Jonathan Müller — @foonathan Express your expectations CppCon 2023-10-03 17Problems with JSON DOM parsers json_value is stringly typed, which requires dynamic memory allocation, manual error handling0 码力 | 143 页 | 736.91 KB | 6 月前3
CppCon2021 Concurrency TS2 Experience My previous C++ project had been in 1990 My initial attempt at RCU bindings in C++ thus used “virtual” This resulted in some pointed feedback 32 © 2021. 33 Again With Curiously Recurring Template Pattern static function? If it returns false, no such deadlocks! bool rcu_deleters_from_retire(rcu_domain& dom = rcu_default_domain()) noexcept; 51 © 2021. 52 What Future Learnings Might There Be? • QEMU developers’ static function? If it returns false, no such deadlocks! bool rcu_deleters_from_retire(rcu_domain& dom = rcu_default_domain()) noexcept; • Maybe rcu_retire()? Type trait saying beg/borrow/steal thread0 码力 | 58 页 | 1.62 MB | 6 月前0.03
hazard pointer synchronous reclamationbj> { Key k; /* etc */ }; hazard_pointer_domain dom_; // other members void erase(Key k) { Obj* obj = foo_remove_obj(k); obj->retire(dom_); } }; • Works. The domain and all objects retired0 码力 | 31 页 | 856.38 KB | 6 月前3
Class Layoutdiscussing 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 | 6 月前3
Breaking Dependencies: The SOLID Principlessquare }; class Shape { public: explicit Shape( ShapeType t ) : type{ t } {} virtual ~Shape() = default; ShapeType getType() const noexcept; private: ShapeType type; }; : Shape{ circle } , radius{ rad } , // ... Remaining data members {} virtual ~Circle() = default; 29 OCP: A Procedural Approachenum ShapeType { circle, square }; }; class Shape { public: explicit Shape( ShapeType t ) : type{ t } {} virtual ~Shape() = default; ShapeType getType() const noexcept; private: ShapeType type; }; class0 码力 | 96 页 | 2.14 MB | 6 月前3
Back to Basics: Designing Classes (part 1 of 2)Shape virtual draw() = 0 Circle Square OpenGLSquare virtual draw() MetalSquare virtual draw() OpenGLCircle virtual draw() MetalCircle virtual draw() virtual serialize() = 0 virtual draw() draw() virtual draw() OpenGLLittleEndianSquare virtual serialize() OpenGLBigEndianSquare virtual serialize()Designing the Shape Hierarchy 22 Shape virtual draw() = 0 Circle Square OpenGLSquare virtual virtual draw() MetalSquare virtual draw() OpenGLLittleEndianSquare virtual serialize() OpenGLBigEndianSquare virtual serialize() OpenGLLittleEndianCircle virtual draw() virtual serialize()0 码力 | 87 页 | 5.64 MB | 6 月前3
Many Ways to Kill an Orc (or a Hero)for that relationship to be usable by client code • The base class usually exposes at least one virtual member function when this happens 29What this is about? import std; // or #include, ew name, int life) : name_{ name }, life_{ life } { } virtual std::string name() const { return name_; } // <-- virtual ~Character() = default; // <-- // alive(), dead() , struct Damageable { virtual void suffer(int) = 0; virtual ~Damageable() = default; }; 59A first attempt… // ... class Character : virtual public Damageable { std::string name_; 0 码力 | 202 页 | 1.26 MB | 6 月前3
共 178 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
相关搜索词
JourneyIntoNonVirtualPolymorphismOptimizingAwayFunctionsMayBePointlessBehaviorTreeCPPTaskPlanningforRobotsandAgentsExpressYourExpectationsFastCompliantJSONPullParserWritingRobustApplicationscppcon2021ConcurrencyTS2hazardpointersynchronousreclamationClassLayoutBreakingDependenciesTheSOLIDPrinciplesBacktoBasicsDesigningClassespartofManyWaysKillanOrcorHero













