why c isn t c enough
Download
Skip this Video
Download Presentation
Why C++? Isn’t C# enough?

Loading in 2 Seconds...

play fullscreen
1 / 8

Why C++? Isn’t C# enough? - PowerPoint PPT Presentation


  • 123 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Why C++? Isn’t C# enough?' - nasia


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
why c isn t c enough

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

Kate Gregory

Gregory Consulting

what c has that others don t
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
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

}

}

}

deterministic destruction1
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
  • }
managed code optimizations
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

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
using other languages
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

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

C++  CLR
ad