Why c isn t c enough
This presentation is the property of its rightful owner.
Sponsored Links
1 / 8

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


  • 91 Views
  • Uploaded on
  • Presentation posted in: General

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.

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.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


  • Login