Tag Archives: cplusplus

Finally, No

Why doesn’t C++ have a finally block? Here’s some Java. void userFunction() { f = new Resource(); f.open(); try { // might throw buffer = f.read(); } finally { f.close(); } useBuffer(buffer); } It’s tempting, after you’ve had a finally for a while to think that it’s necessary for proper resource management in the face… Read More »

Not Everything Is A Reference

I like Java as a language. Kind of. It’s strongly and statically typed, has object oriented syntax, reflection, exceptions, and interfaces (interfaces being one of the few features that I think C++ is missing). Dynamically typed languages encourage sloppiness, and don’t help you avoid sloppiness, and the overriding feature of all good software is that… Read More »

Copy and Swap Idiom

I learned a new trick today, while reading about C++11 (of which more to come). It’s a technique I wish I’d known about a long time ago, as it addresses an issue I’ve always thought C++ had – forcing you to duplicate code. That issue is addressed even more thoroughly with C++11, which has introduced… Read More »

Valgrind II — helgrind

Last time we looked at valgrind’s memory leak detector, memcheck. This time we’ll be looking at an even more difficult to catch class of bug, thread race conditions. First let’s be clear what a thread race is: a race is when two threads run code that access the same piece of memory. The outcome is… Read More »

Valgrind I — memcheck

In this series I’m going to give you a quick tour of the valgrind tool suite. valgrind is useful for finding those hard-to-find, serious-repercussion bugs that can sneak into your code. Consider this C++ program: // C++ #include <iostream> // C #include <stdlib.h> // OS #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> using namespace… Read More »