Why C Isnt C enough Kate Gregory Consulting

  • Slides: 8
Download presentation
Why C++? Isn’t C# enough? Kate Gregory Consulting

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

What C++ has that others don’t Can generate native code C++ interop – the

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

Deterministic Destruction Nested “using”s in C# are hard to read { using(Sql. Connection conn

Deterministic Destruction Nested “using”s in C# are hard to read { using(Sql. Connection conn = new Sql. Connection(conn. String) ) { // work with the connection in some way using(Sql. Command cmd = new Sql. Command(query. String, conn) ) { // work with the command } } }

Deterministic Destruction Automatic scope is easier { Sql. Connection conn(conn. String); // work with

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

Managed Code Optimizations Compiler optimizes MSIL Even when generating verifiable code Some optimizations supported

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

Profile Guided Optimization Source Compile with /GL Object files Link with /LTCG: PGI Instrumented

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

Using Other Languages Visual C++ allows you to include code from multiple languages in

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. cs C# Compiler c. netmodule D: >csc /t: module c. cs C++ Linker C++ Code C# Code

C++ CLR C++ Features Deterministic cleanup, destructors Templates Native types Multiple inheritance STL, generic

C++ CLR 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