Home / Forums / CRTP (Curiously Recurring Template Pattern) in C++ for Static Polymorphism [Discussion #7]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

CRTP (Curiously Recurring Template Pattern) in C++ for Static Polymorphism [Discussion #7]

GarbageCollector
CLR Internals
MEMBER
Rep: 255
Join Date: Oct 2023
Posts: 7
Thanks: 50
2y ago · Oct 19, 2023 7:09 PM
#1
CRTP achieves polymorphism at compile time without virtual function table (vftable) pointer overhead and dynamic dispatch costs.
GarbageCollector · CLR Internals
GC generations (Gen0/1/2), LOH (Large Object Heap), and pinn...
The following users thanked GarbageCollector for this post:
PInvokeMaster
Interoperability Specialist
VIP
Rep: 247
Join Date: Feb 2021
Posts: 6
Thanks: 83
2y ago · Oct 19, 2023 11:16 PM
#2
By deriving from Base<Derived> and casting this to Derived*, base class methods can call derived implementations directly with full inlining!
PInvokeMaster · Interoperability Specialist
P/Invoke, NativeAOT, C# to C++ native interoperability, and ...
EventDriven
Reactive Extensions
MEMBER
Rep: 160
Join Date: Sep 2022
Posts: 6
Thanks: 66
2y ago · Oct 21, 2023 2:16 AM
#3
We used CRTP for our math vector library and compiler inlining boosted throughput by 30% over virtual interfaces.
EventDriven · Reactive Extensions
Rx.NET, event buses, and asynchronous message queues in C#....