Articles & Books

Are contiguous C++ arrays really faster than Java/C# ArrayLists? -- StackOverflow

When you see anyone claim performance parity between <other language> and C++, one of the first things to look for is whether the C++ version of their test code is correctly using arrays and traversing them in order. If the test code is just doing equivalent pointer-chasing in both languages, the performance comparison is largely meaningless because the program is probably memory-bound and not properly written to use C++'s default container (vector).

Note: The question below has been modified since originally posted and now shows more reasonable numbers that demonstrate contiguous arrays are indeed faster. The comments are still enlightening to read, however.

Today on SO:

Unable to reproduce: C++ Vector performance advantages over C# List performance

At Microsoft's BUILD conference Herb Sutter explained that C++ has "Real Arrays" and C#/Java languages do not have the same or sort of.

I was sold on that. You can watch the full talk here http://channel9.msdn.com/Events/Build/2014/2-661

Here is a quick snapshot of the slide where he described this. http://i.stack.imgur.com/DQaiF.png

But I wanted to see how much difference will I make.

So I wrote very naive programs for testing, [...] Here are the results on my dell laptop with Core i7 processor:

count       C# (List<string>)   C# (ArrayList)     C++  
1000           24 ms              21 ms             7 ms      
10000         214 ms             213 ms            64 ms    
100000  2 sec 123 ms       2 sec 125 ms           678 ms

Declare functions noexcept wherever possible? -- Scott Meyers

Scott Meyers' work on his new "Effective C++" book, tentatively titled Effective Modern C++, progresses with an updated draft item:

Declare functions noexcept wherever possible?

by Scott Meyers

From the article:

In the comments following my last post, there was some controversy regarding the wording of my advice on noexcept functions. My advice is "Declare functions noexcept whenever possible." Some people appear to be concerned that this could be misconstrued as advocating noexcept even when it makes no sense, but I think the advice is a reasonable conclusion to the Item that supports it. I posted a draft version of that Item in early February, but I've revised the draft since then, and I'm making the current draft available now: ...









Control Structures in C++ -- Prashant Sharma

[For very new programmers, this is a basic review of the control flow language features available in C++ -- most of them also valid C, but at our request now with coverage also of the C++-specific range-for loop. -- Ed.]

Now on life`n`gadget:

Control Structures in C++ (Flow of Control)

by Prashant Sharma

From the article contents:

1 Control Structures in C++

1.1 Introduction

1.2 Selection Structure (Branching Statements)

1.2.1 if Statement

1.2.2 if-else Statement

1.2.3 Nested if else Statement

1.2.4  switch Statement

1.2.4.1 switch vs if-else

1.3 Looping Structure(Iterative Statements)

1.3.1 Elements of Looping Structure

1.3.2  for-loop

1.3.3 Range-for statement (range based for-loop) New C++11 Feature

1.3.4 while-loop

1.3.5 do-while loop

1.3.6 Related

C++ Status

A follow up on my proposal series & C++14 post:

C++ Status

by Jens Weller

From the Article:

This is the followup I promised after my last series for Issaquah. The current status of the standardization is that C++14 is on its final way to become a new ISO Standard, as you can see on the C++ Status Page of isocpp.org.

Quick Q: Is std::array movable any better than a plan C array? -- StackOverflow

Quick A: Yes.

Today on SO:

Move constructors and std::array

According to N3485 §23.3.2.2:

(...) the implicit move constructor and move assignment operator for array require that T be MoveConstructible or MoveAssignable, respectively.

So, std::array supports move semantics if the type of its elements does. Great!

However, what does this really mean? I tend to picture this type as a safer version of an array providing an STL-compliant interface but, if this is true, then how can an std::array move-construct its elements? Can I do the same with an ordinary array?

C++11/14 Standard & Standardization--Peter Sommerlad

Peter Sommerlad on C++11 and C++14 Standard(s) and Standardization:

Peter Sommerlad on C++11 and C++14 Standard(s) and Standardization

Created by Peter Sommerlad March 6, 2014

From the presentation:

Why is C++ in again?

• more computing per Watt!
  • mobile - battery powered
  • servers - cloud computing
  • high-performance computing & GPUs
• better abstractions than C
  • without performance price (e.g. of a VM)
  • embedded (higher-level type safety)
  • security (buffer overruns, pointers)

Slides (PDF)