RSSAmplifier

Blog

antonym.org

Articles on C++ programming, Software Engineering and technology.

antonym.orgRSS feed ↗10 posts

Latest posts

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

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. The final keyword in C++11 can be applied to either an entire class or a method. When applied to a class, it signifies that the class is closed to derivation ; that is, you cannot create a class…

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…

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…

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…

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. Instead of using a bare pointer type in C++, the modern C++11 style is now to use std::unique_ptr . This class will automatically free the allocated memory…

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() . char * buffer = malloc ( BUFFER_SIZE ); fill_buffer ( buffer , BUFFER_SIZE ); process_buffer ( buffer , BUFFER_SIZE ); free ( buffer ); Some of the problems with this approach were: malloc() might fail if the system is running low on…

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? It’s compiled , so it’s fast. Rust uses LLVM as the compilation engine, and benefits from all its optimisation and native code generation support…

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. Mutex Examples The full source for the sample applications is provided below. It is designed to be fully portable, and has been tested on Mac OS X and…

Threading with Boost - Part V: Condition Variables

In multithreaded programs, mutexes are used as a lock to protect shared resources and enforce atomic operations. This is useful to manage concurrent access, but what about when one thread needs to asynchronously signal to another thread that an event has occured or a condition is true? One possible solution would be to continuously poll a variable to detect a change in state. This is incredibly…