Bits by Gavin Baker

C++11 and Override

The new override modifier can be applied to a virtual method in C++11, and instructs the compiler that the method is intended to override a virtual method defined in the parent class. The primary advantage is that typos and mismatched method signatures that would have resulted in subtle bugs and unintended runtime bheaviour before can now be detected at build time and easily corrected.

C++11 and Final

One of the lesser known – but still very useful – enhancements to C++11 is the addition of the final keyword. This essentially mirrors the final feature in Java, which has existed since its inception.

C++11 Range-based for Loops

The humble for loop is one of the oldest control flow control constructs in the Algol family of languages. Yet while other languages have extended their syntax to allow for loops to do all sorts of crazy and useful things beyond iterate over a range of numbers, C and C++ have remained steadfast – until now.

The for loop finally has a new syntax to better support iterators and ranges, just two great new features in C++11. So you can now easily iterate over much more than just numbers.

C++11 Futures

Concurrency is one of the most significant challenges facing software development today. As the gains in processor performance diminish year over year, additional cores have become the norm. For some years now, multicore processors have become the norm.

Taking advantage of multiple cores has usually required writing multithreaded code, which can be complex to design and debug. One of my favourite new features in the C++11 standard library is the future module. This provides an extra layer of abstraction over threads, providing a simple mechanism for asynchronous (ie. concurrent) processing.

C++11 Smart Pointers: Shared Pointer

In the last article on smart pointers, we looked at std::unique_ptr, which provides a simple and safe smart pointer to wrap heap allocations. As the name implies, this smart pointer type cannot be shared between multiple threads.

So then how can you ensure that the memory is freed once all referring threads have finished with the resource? This is especially difficult when the thread lifecycle is non-deterministic.

C++11 Smart Pointers: Unique Pointer

C++11 introduces many significant improvements to the language and runtime. One of the most important is to do with memory management – specifically, smart pointers. The unique_ptr makes managing dynamically allocated memory safe and simple.

Modern C++11 Memory Management

Memory management in low level code has changed slowly over the years. In traditional C code, you would allocate memory with malloc() and release it with free().

What Is Rust?

Rust is a compiled, hybrid imperative/object- oriented/functional language. It appeals directly to any C++ developer who has battled with memory management, and Python developers who long for faster code. So why might you be interested in learning Rust?

Threading With Boost - Part IV: Mutex Examples

This article continues the series on threading with Boost, by looking in depth at several sample programs which illustrate different aspects of mutexes. We look at the code, and discuss how it is implemented, including how to avoid common problems.

Threading With Boost - Part III: Mutexes

In Part I of this series on Boost threading, we looked at the basics of how to create and run threads using the Boost libraries. Then we reviewed the main issues encountered with multithreading code in Part II: Threading Challenges. One of the biggest challenges is safely managing concurrent access to a resource. A Mutex provides a way to serialise access to a shared resource, such that only one thread is accessing the data at any given time, to ensure your data is consistent. In this article, we look at how to create and use Boost mutexes.