· For the last decade, the majority of my dev work has leveraged the.NET Framework for construction of information systems. However, my interest has lain in numerical computing.
· Is it possible to have an increasingly higher level of abstraction and at the same time achieve underlying high performance computing? The prevailing winds say no: C# is aimed at productivity, and C++ is for performance. Garbage collection was great, but do we still need it with the availability of smart pointers? Would you like to leverage GPGPU from.NET? Yes, there is 3rd party Brahma.NET (LINQ to GPU - ), but not much from MS – Accelerator (http://research.microsoft.com/en-us/projects/accelerator/) never made it out of MS Research, and the company is pushing C++ AMP for GPGPU. That’s C++ AMP, not C# AMP. The Win 8 status of XNA is in doubt (via ominous silence), so the only way to program a sufficiently advanced UI for a metro app (i.e. something dazzling that gives competitive advantage by having high barriers of entry, not a XAML LOB form!) so far will be via DirectX, which is only supported in C++.
· Aside from interop, I hadn’t done much in C++ since the 1990s (ATL and DirectX). I spent the last couple of weeks revising. This post describes the resources I used to get back up to speed in an unmanaged world.
October – My Grand C++ Cram
ANSI C++ Language Tutorial
· I started with http://www.cplusplus.com/doc/tutorial/ - These tutorials explain the C++ language from its basics up to ANSI-C++ 2003, including basic concepts such as arrays or classes and advanced concepts such as polymorphism or templates.
· Coming from C#, there are a lot of C++ oddities that this tutorial allowed me to revise and reacquaint myself with. I will blog about these differences in a future post.
· Basics of C++
· Control Structures
· Compound Data Types
o Arrays
o Pointers
· Object Oriented Programming
· Intermediate Concepts
STL Reference
· http://www.cplusplus.com/reference/
· The Standard template library is kind of like System.Collections.Generic for C++. The STL is a collection of functions, constants, classes, objects and templates that extends the C++ language providing basic functionality to perform several tasks, like classes to interact with the operating system, data containers, manipulators to operate with them and algorithms commonly needed. The declarations of the different elements provided by the library are split in several headers that shall be included in the code in order to have access to its components
· C++ Standard Library: Standard Template Library (STL)
· C++ Standard Library: Input/Output Stream Library - Provides functionality to use an abstraction called streams specially designed to perform input and output operations on sequences of character, like files or strings.
Visual C++ reference for Windows Runtime
· Allot of detritus has accumulated in the C++ APIs pile over the past 2 decades. MS is pushing 'modern C++', forcing Win8 C++ developers to use better practices. Visual C++ in Visual Studio 11 for Windows Developer Preview has a new programming model for creating Metro style apps and components. One of the primary features of the new model is the abstract binary interface, or ABI, which defines an interface for inter-language communication. The new programming model is based on an updated version of COM, but the way that you program against this new model is more simple and natural than old-style COM programming.
· Windows Runtime objects and ref new
· Strings
· Interfaces and Parameterized Interfaces
· Arrays
· Enums
· Events
· Platform::Uri and Guid types
· Casting between C++ and WinRT types
· Boxing
C++/CLI
· Allot of the modern C++ stuff seems similar to C++/ CLI, so I revised that for good measure - C++/CLI for the C# programmer - http://www.c-sharpcorner.com/UploadFile/b942f9/9697/
· I also looked at the Differences between C++/CLI and WinRT C++ - http://social.msdn.microsoft.com/Forums/en-GB/winappswithnativecode/thread/0aec2f93-de7e-4f2b-8090-17ceb34ed759
C++ 11
· http://en.wikipedia.org/wiki/C%2B%2B11
· The next thing I looked into was the latest version of C++. The Wikipedia article was a very informative source. I would say the biggest change here is the inclusion for a very powerful expression of Lambda Functions in C++. Heres the TOC:
· 1 Candidate changes for the impending standard update
· 2 Extensions to the C++ core language
· 3 Core language runtime performance enhancements
o 3.1 Rvalue references and move constructors
o 3.2 Generalized constant expressions
o 3.3 Modification to the definition of plain old data
· 4 Core language build time performance enhancements
· 5 Core language usability enhancements
o 5.5 Lambda functions and expressions
o 5.6 Alternative function syntax
o 5.7 Object construction improvement
o 5.8 Explicit overrides and final
o 5.10 Strongly typed enumerations
o 5.12 Explicit conversion operators
o 5.15 Identifiers with special meaning
· 6 Core language functionality improvements
o 6.4 Multitasking memory model
o 6.6 Explicitly defaulted and deleted special member functions
o 6.9 Allow sizeof to work on members of classes without an explicit object
o 6.10 Allow garbage collected implementations
· 7 C++ standard library changes
o 7.1 Upgrades to standard library components
o 7.6 General-purpose smart pointers
o 7.7 Extensible random number facility
o 7.9 Polymorphic wrappers for function objects
o 7.10 Type traits for metaprogramming
o 7.11 Uniform method for computing the return type of function objects
· 8 Features planned but removed or not included
· 9 Features to be removed or deprecated
C++ Programming Wiki booklets
· I found some nice resources on esoteric C++ topics here:
· STL - http://en.wikibooks.org/wiki/C++_Programming/STL
o The Standard Template Library (STL) offers collections of algorithms, containers, iterators, and other fundamental components, implemented as templates, classes, and functions essential to extend functionality and standardization to C++. STL main focus is to provide improvements implementation standardization with emphasis in performance and correctness.
· TMP - http://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming
o Template meta-programming refers to uses of the C++ template system to perform computation at compile-time within the code.
· Smart Pointers - http://en.wikibooks.org/wiki/C++_Programming/Operators/Pointers/Smart_Pointers
o Using raw pointers to store allocated data and then cleaning them up in the destructor can generally be considered a very bad idea since it is error-prone. Even temporarily storing allocated data in a raw pointer and then deleting it when done with it should be avoided for this reason. For example, if your code throws an exception, it can be cumbersome to properly catch the exception and delete all allocated objects. Smart pointers can alleviate this headache by using the compiler and language semantics to ensure the pointer content is automatically released when the pointer itself goes out of scope.
· RTTI - http://en.wikibooks.org/wiki/C++_Programming/RTTI
o RTTI refers to the ability of the system to report on the dynamic type of an object and to provide information about that type at runtime (as opposed to at compile time), when utilized consistently can be a powerful tool to ease the work of the programmer in managing resources.
· C++ Garbage Collection ( a little sparse) - http://en.wikibooks.org/wiki/C++_Programming/Compiler/Linker/Libraries/Garbage_Collection
· Libraries (including popular 3rd party libraries) - http://en.wikibooks.org/wiki/C++_Programming/Compiler/Linker/Libraries
o Additional functionality that goes beyond the standard libraries (like garbage collection) are available (often free) by third party libraries, preventing wheel (and square wheel) re-invention.
· The Boost Library (nice overview!) - http://en.wikibooks.org/wiki/C++_Programming/Libraries/Boost
o The "w:Boost (programming)") ( http://www.boost.org/ ) provides free, peer-reviewed , open source libraries that extend the functionality of C++. Boost is like the BCL for C++.
· Optimization - http://en.wikibooks.org/wiki/C++_Programming/Optimization
o the use of virtual member functions, the right container, etc
· Win32 - http://en.wikibooks.org/wiki/C++_Programming/Code/API/Win32
o most direct way to interact with Windows for software applications. Lower level access to a Windows system, mostly required for device drivers, is provided by the Windows Driver Model .
· C++ Programming/Threading
o http://en.wikibooks.org/wiki/C++_Programming/Threading
Concurrency Runtime
· Next I read through the section on MSDN that discussed parallelism on the CPU - http://msdn.microsoft.com/en-us/library/ee207192.aspx - this set of APIs raises the level of abstraction so that you do not have to manage the infrastructure details that are related to concurrency. You can also use it to specify scheduling policies that meet the quality of service demands of your applications. Coming from TPL, the were a lot of programmatic similarities that were evident. CCR goes a step further than the TPL though: It exposes UMS (user mode scheduling), allowing you to set task priority, and preemptively release the CPU from a non-busy thread.
· Parallel Patterns Library (PPL) - http://msdn.microsoft.com/en-us/library/dd492418.aspx
o builds on the scheduling and resource management components of the Concurrency Runtime
· Asynchronous Agents Library - http://msdn.microsoft.com/en-us/library/dd492627.aspx
o a template library that promotes an actor-based programming model and in-process message passing for coarse-grained dataflow and pipelining tasks. Very similar concepts to Axum, MPI.NET, TPL 4.5 DataFlow and F# DataFlowVariable
· Task Scheduler (Concurrency Runtime) - http://msdn.microsoft.com/en-us/library/dd984036.aspx
C++ AMP
· Following this I got round to GPGPU – I read through
· http://msdn.microsoft.com/en-us/library/hh265137(VS.110).aspx and, http://www.danielmoth.com/Blog/
· C++ Accelerated Massive Parallelism accelerates execution of C++ code by taking advantage of the data-parallel hardware that is generally present as a GPU on a discrete graphics card. The C++ AMP programming model includes multidimensional arrays, indexing, memory transfer, tiling, and a mathematical function library. C++ AMP language extensions and compiler restrictions enable you to control how data is moved from the CPU to the GPU and back, which enables you to control the performance impact of moving the data back and forth.
· Basically this is a C++ abstraction over HLSL for GPGPU – just like OpenCL is over CUDA. I must say that the programmatic concepts easily transferred across from what I had previously learned by going through MS Accelerator, but allot more configurable.
· I especially liked the tile_static modifier – a type of shared memory for a subset of GPU threads – think rollup and linear algebra block matrices!
Windows Programming in C++
· Currently going through using the Win32 API - http://msdn.microsoft.com/en-us/library/ff381399(VS.85).aspx
o Introduction to Windows Programming in C++ - describes some of the basic terminology and coding conventions used in Windows programming.
o Module 1. Your First Windows Program - create a simple Windows program that shows a blank window.
o Module 2. Using COM in Your Windows Program - introduces how COM underlies many of the modern Windows APIs.
o Module 3. Windows Graphics - Windows graphics architecture, with a focus on Direct2D.
o Module 4. User Input - mouse and keyboard input.
· At some point, I'll get back to that Windows Internals book too!
Next Month
October's nearly over, and aside from reading the Roslyn docs and a JQuery book, (and my day job!!), I've learned and relearned allot of C++. So whats next?
COM
· I'm rearing to revise this stuff – its been a while since my programming life revolved around COM (I vaguely remember monikers, IDL etc) - http://msdn.microsoft.com/en-us/library/ee663262(VS.85).aspx. Heres some links:
o Component Object Model (COM) COM is a platform-independent, distributed, object-oriented system for creating binary software components that can interact. COM is the foundation technology for Microsoft's OLE (compound documents) and ActiveX (Internet-enabled components) technologies.
o Automation - enables software packages to expose their unique features to scripting tools and other applications..
o Microsoft Interface Definition Language (MIDL) - defines interfaces between client and server programs. The MIDL compiler in the Platform SDK enables you to create the interface definition language (IDL) files and application configuration files (ACF) required for RPC interfaces and COM/DCOM interfaces. MIDL also supports the generation of type libraries for OLE Automation.
o Structured Storage - provides file and data persistence in COM by handling a single file as a structured collection of objects known as storages and streams.
DirectX
· I recently gave a course on XNA, so am ready to deep dive back into this platform - http://msdn.microsoft.com/en-us/library/ee663274(VS.85).aspx
The Boost C++ Libraries
· You just cannot be proficient in C++ without Boost - http://en.highscore.de/cpp/boost/frontpage.html. As I stated, this is the BCL of C++.
o Chapter 7: Asynchronous Input and Output
o Chapter 8: Interprocess Communication
WDK – Windows Driver Kit
· I know next to nothing about this!!!.aspx) – I am very curious about how to write code in kernel mode.
Optimizing C++ Wikibook
· To master something, you have to know how to tweak it - http://en.wikibooks.org/wiki/Optimizing_C%2B%2B
o Performance improving features
o Performance worsening features
o Constructions and destructions
o Allocations and deallocations
· General optimization techniques
o Sorting
o Allocations and deallocations
o Constructions and destructions
o Pipeline
As Yoda stated – C# devs: "You must unlearn what you have learned" - http://www.youtube.com/watch?v=FDezrybpuO8
Cheers,
Josh
