We usually work with C++ at Anticto, like most people doing video games technology. C++ is a great language with more tools and libraries than any other. Ok, i cannot prove that, but you get what I mean. C++ is a systems language with pretty low level access. As such, it won’t stop you from causing all sorts of crashes. The most common of them are usually related to memory management and this includes bugs that may only happen sometimes, in some computers, or even in some compiler configurations. They may be hard to catch and solve, but luckily, there is Valgrind.

Valgrind logo.png
Image rights: Valgrind Dev Team

For most people Valgrind is a memory debugger, but it is actually a framework to develop tools to run together with a program. The best known of them is indeed the memory debugger, but there are several that we use:

  • Memcheck: a memory access error and leak detector
  • Massif: a memory profiler for both heap and stack
  • Cachegrind: a low level performance profiler

Additionally, we use the KCachegrind, massif-visualizer, and the integration in Qt Creator for memcheck, to get more visual feedback of valgrind results. We also use it in our internal Continuous Integration system to find problems before they get to production versions.

If you are a Windows-only developer, I am sorry for you. Also, you won’t be able to use Valgrind, due to OS-level functionality missing. We use it basically under Linux, but in theory it also supports MacOS and Android in several architectures.

After using Valgrind’s memory checker in many projects, I wouldn’t dare to release any software to the public without “valgrinding” it first. It is a humbling experience, and sometimes when you look at the results it makes you think valgrind is not working properly, but in the end… Valgrind Is Always Right.

The other sort of program defects that is as common as memory errors are concurrency issues. Valgrind has tools to detect some of them but we haven’t used them yet. That’s a big TODO in our list.

For performance, Valgrind is ok, but we often resort to manual code instrumentation, and platform-specific tools which are usually great on consoles. Also, Intel and AMD are providing some excellent tools like VTune or uProf. For graphics, there are excellent tools as well, but this is an entirely different subject for another time.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.