Articles & Books

How Dropbox Uses C++ for Cross-Platform iOS and Android Development -- Ole Begemann

dropbox.pngDid you know that C++ is a hot language for mobile development? This seems to be widely known among C++ developers, but surprisingly widely unknown in the non-C++ programming community at large. Two of the major reasons why C++ is currently experiencing this surge in mobile interest are:

  • C++'s efficiency and determinism help create power-sipping apps -- ones that not only use fewer CPU cycles, but use them in battery-friendly "bursty" ways that let the CPU sleep frequently, and deterministically let go of expensive resources like sensors immediately when they're not needed.
  • C++'s portability makes it the only cross-platform language that can target every major and minor mobile phone and tablet platform -- including iOS, Android, Windows and Windows Phone, and Blackberry -- never mind of course as usual also targeting every other platform and environment too, from desktops to servers to datacenters where it's already the language of choice in companies from Google to Facebook.

In that vein, here's a post from just before the U.S. long weekend about using C++ for cross-platform mobile development.

Expect to see more news like this. Also, expect to see talks on using C++ for modern cross-platform mobile development as one of the hot topics at CppCon this September.

How Dropbox Uses C++ for Cross-Platform iOS and Android Development

by Ole Begemann

From the article:

When work started on the Mailbox app for Android, the team made the choice to write a large portion of the non-UI code in C++ — rather than rewriting the entire app in Java — with the goal of sharing that common C++ layer between iOS and Android. The iOS app used Core Data at the time, so migrating it off of Core Data to the shared C++ library was also part of the process. C++ seemed like an obvious choice because it is available on every platform and team members preferred the language over Java.

The Carousel team made the same choice since launching simultaneously on iOS and Android was an important goal from the start.

Quick Q: Why can't a data member be in a lamba capture list -- StackOverflow

Quick A: Because you can only capture local (stack) objects, including function parameters, and to access a data member in a member function you capture the local variable this.

Today on SO:

Why can't a data member be in a lamba capture list

I have a class foo that has bar as a member variable.

In another member function of the class, I'm writing a lambda function:

[bar](void){}

But I can't include bar in the capture list. Why is that?

Vector of Objects vs Vector of Pointers Updated -- Bartlomiej Filipek

More in the "contiguous enables fast" department:

Vector of Objects vs Vector of Pointers Updated

by Bartlomiej Filipek

From the article:

For 1000 particles we need on the average 2000 cache line reads! This is 78% more cache line reads than the first case! Additionally Hardware Prefetcher cannot figure out the pattern -- it is random -- so there will be a lot of cache misses and stalls.

In our experiment the pointer code for 80k of particles was more 266% slower than the continuous case.

ACCU 2014 talk slides now available

[Ed: Here's a candidate for the most hilarious thing you'll probably see today: Kevlin Henney's slide deck, including a link to this @netbat tweet.]

The recent ACCU 2014 was another resounding success, and many of the talk slides have now been posted. You can find them here:

Slides, Photos, Blogs via #accu2014 (accu.org)

Some fun C++ highlights with slides available include:

  • Dietmar Kuhl · Performance Choices
  • Howard Hinnant · Everything You Ever Wanted To Know About Move Semantics (and then some)
  • Hubert Matthews · Where is C++ headed?
  • Jonathan Wakely · There Ain't No Such Thing As A Universal Reference
  • Jonathan Wakely · The C++14 Standard Library
  • Kevlin Henney · Immutabilty FTW!
  • Marshall Clow · C++ Undefined Behavior -- what is it, and why should I care?
  • Olve Maudal · C++ Pub Quiz
  • Pattabi Raman · Random number generation in C++ -- present and potential future
  • Peter Sommerlad · C++14 an overview on the new standard for C++(11) programmers
  • Steve Love · Range and Elevation -- C++ in a modern world
  • ... and more (see the page).

Stopping the Spew -- Tony DaSilva

Today on Bulldozer00:

Stopping the Spew!

by Tony DaSilva

From the article:

Every C++ programmer has experienced at least one, and most probably many, “Template Spew” (TS) moments. You know you’ve triggered a TS moment when, just after hitting the compile button on a program the compiler deems TS-worthy, you helplessly watch an undecipherable avalanche of error messages zoom down your screen at the speed of light. ...

... Fear not, because help is on the way via C++14 in the form of "concepts lite".

Quick Q: How do generic lambdas work? -- StackOverflow

Quick A: They generate a templated operator(), and that means you can call the same closure object with all sorts of different parameters and it just stamps out the function for each set of parameter types.

A "new classic" question on SO, classic because it was posted a year ago, but newly relevant because now the mainstream compilers are implementing the feature:

How does generic lambda work in C++14?

How does generic lambda work (auto keyword as argument type)?

Is it similar to templates where for each different argument type compiler generates functions with the same body but changed types or is it more similar to Java's generics?

Code example:

auto glambda = [](auto a) { return a; };

Fast Polymorphic Collections with Devirtualization -- Joaquín M López Muñoz

munoz.pngStill on the theme of "contiguous enables fast," a followup on the recent "Fast Polymorphic Collections" article:

Fast Polymorphic Collections with Devirtualization

by Joaquín M López Muñoz

From the article:

The poly_collection template class we implemented for fast handling of polymorphic objects can be potentially speeded up in the case where some of the derived classes it manages are known to the compiler at the point of template instantiation...

Allowing for the specification of a list of statically known derived class types as part of a poly_collection instantiation opens up possibilities for internal performance optimizations that do not impact the usage interface of this template class. The actual improvements achieved depend very much on the compiler being used, but in general are greater when passing polymorphic functors (such as generic lambdas) to for_each and qualifying virtual functions as final where possible.