Tutorials

Migration to Hugo

tl;dr This blog has been migrated from Wordpress to Hugo (a static site generator). As with the previous migration (from tumblr to Wordpress) the comments have been lost (although there were only 2), and you’ll need to update your RSS feed link to this. I have a few reasons for this; one being that I’m already paying for a webhost (so I might as well make use of it), and another being that a website of purely static content is lightweight and fantastically secure.

[C++] A safer array size macro

Introduction Array size macros in C++ are typically ported from C, and so often end up looking something like this. #define ARRAY_SIZE_UNSAFE(A) (sizeof(A)/sizeof(*(A))) This will work, however it has no type safety, so you can pass it both an array or a pointer to an array. This post shows how templates can be used in C++ to create a safer array size macro (this is the same technique that _countof uses in MSVC).

[C++] An exercise in optimisation #1 - ImmutableString

Introduction This post outlines a problem I had to solve regarding using a string as a key for a hash table, and the steps that were taken to optimise the problem by applying the solution of an immutable string type. I may make this into a series if I can find interesting enough examples that I can suitably simplify the code for. The Problem I was creating a key -> value pair map for use with a C++ serialisation system; the keys had to be strings as they were used as identifiers for JSON, and around 99% of the time the key would be a string literal.

[C++] Bit-flags

Introduction Bit-flags are used in C and C++ to save memory by allowing you to pack multiple boolean variables into a single integer variable. While they are very good at this, the syntax for using them isn’t exactly the easiest to read, so I thought I’d share a trick we use at work to deal with bit-flags. The Code struct Flags8 { union { uint8_t allFlags; struct { bool flag1 : 1; bool flag2 : 1; bool flag3 : 1; bool flag4 : 1; bool flag5 : 1; bool flag6 : 1; bool flag7 : 1; bool flag8 : 1; }; }; }; The code above shows a struct containing a union between an 8-bit unsigned integer, and another struct containing a series of bit-wide booleans (that’s what the : 1 does).

Introduction to premake4

Introduction A while back I wrote a blog post based on my experiences using the CMake build system. The conclusion from this was that I found CMake to be a useful tool, but pretty painful to work with due to it using a custom scripting language and being quite lacking in the documentation and support departments. In short, it was something I tolerated rather than enjoyed using. These issues meant I was open to alternatives, but I never looked for any until I read an AltDevBlogADay post on meta build systems which mentioned premake.

My experience using CMake (and a tutorial)

Introduction For those of you that don’t know CMake is a cross platform build system that allows you to define what you want to build and how, before it goes off and creates the correct build scripts for your particular platform and compiler. It is supposed to help you to simplify your build process when compiling for multiple platforms by just having to maintain a single build script that can generate all other build scripts.

Setting up nForce in Windows 7

I’ve recently installed Windows 7 on my main PC, removing the old Vista install. While doing this I had some issues getting my on-board nVIDIA nForce 6 network drivers working, and from looking around the internet, I am not alone. The solution that eventually worked for me is as follows: Shut down your PC and turn it off at the mains for ~20 seconds. Turn your PC back on and boot into Windows, it should now be able to see and use your nForce network adapters to access the internet, however if you restart Windows you will find that the adapters become disabled again.

Setting up Redmine on WebFaction

Update: 26 Nov 2011: I’m informed that WebFaction now has built-in installers for Redmine. Since this is something I have recently had to do, and found the documentation to be out of date, I though I would share this working solution with you all. This is based on Redmine 0.9.x, and thanks to Sean F from WebFaction support, these instructions are mostly his. Go to your WebFaction control panel and create a new MySQL database, making a note of the database name and password.

[C++] Anything to/from a Hex String

Introduction I recently needed to be able to convert any instance of an object in C++ to a file so it could be serialised, and then restored later; I did most of this by writing out each member variable of the object individually at the most basic level. This works fine and is easy enough to implement; but then came the time to do the “generic” version, the version that could write out any object (such as a struct) as a whole.

[C++] Pointer Fun – SafeDelete

Introduction SafeDelete and SafeArrayDelete are functions that will delete the data a pointer points to before setting it to NULL. The idea being that they leave the pointer in a safe NULL state so that you don’t try and use a pointer which points to invalid memory. How to - With a Macro You can implement a SafeDelete set-up using a macro, it might well look something like this: