1 / 8

Why C++? Isn’t C# enough?

Why C++? Isn’t C# enough?. Kate Gregory Gregory Consulting. What C++ has that others don’t. Can generate native code C++ interop – the fastest and easiest Templates and generics Deterministic destruction Optimized MSIL PGO for native and managed code .NET Linking.

nasia
Download Presentation

Why C++? Isn’t C# enough?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Why C++? Isn’t C# enough? Kate Gregory Gregory Consulting

  2. What C++ has that others don’t • Can generate native code • C++ interop – the fastest and easiest • Templates and generics • Deterministic destruction • Optimized MSIL • PGO for native and managed code • .NET Linking

  3. Deterministic Destruction • Nested “using”s in C# are hard to read { using(SqlConnection conn = new SqlConnection(connString) ) { // work with the connection in some way using(SqlCommand cmd = new SqlCommand(queryString, conn) ) { // work with the command } } }

  4. Deterministic Destruction • Automatic scope is easier • C++ destructor maps to CLR “Dispose” • Both directions • Less code, more control • { • SqlConnection conn(connString); • // work with the connection in some way • SqlCommand cmd(queryString, %conn); • // work with the command • // don’t call Dispose or Close • }

  5. Managed Code Optimizations • Compiler optimizes MSIL • Even when generating verifiable code • Some optimizations supported on MSIL • Inlining • Loop unrolling • Loop invariant code motion • Common subexpression elimination • Copy propagation • Expression optimizations • Whole program optimization now supported for /clr code

  6. Object files Compilewith /GL Source Object files Link with /LTCG:PGI Instrumented Image ` Scenarios Profile data Instrumented Image Output Profile data Link with /LTCG:PGO Optimized Image Object files Profile Guided Optimization

  7. Using Other Languages • Visual C++ allows you to include code from multiple languages in a single file assembly a.cpp C++ Compiler a.obj EXE D:\>cl /c /clr a.cpp C++ Linker C++Code C#Code c.cs C# Compiler c.netmodule D:\>csc /t:module c.cs

  8. C++ Features Deterministic cleanup, destructors Templates Native types Multiple inheritance STL, generic algorithms Pointer/pointee distinction Copy construction, assignment CLR Features Garbage collection, finalizers Generics Reference and value types Interfaces Verifiability Security Properties, delegates, events C++  CLR

More Related