Packing Data Files into Compiled Executables
Have you ever wanted to distribute a compiled binary that included data files packed into the executable file? Embedding a Data File Before Compilation You can do this before compilation by encoding the file into a binary representation, and then…
Generating a Cross-Platform Unique Machine Fingerprint
Sometimes you need a program to know if it is running on the same machine. There are a lot of purposes for this, but a common one is if you are writing a licensing module. You want to generate a…
Fixing File Descriptor Leaks in Long-Lived Servers
So you’ve created a socket server that opens sockets over TCP/IP. After running it for a few hours under heavy load the operating system kills your process with the message “Too many open files”. What happened? The problem On most…
Implementing Read/Write Locks Portably
In multi-threaded programs you often find a usage pattern where many more threads need to read a shared resource than write to it, and where reading the resource would be thread-safe without mutexes if it is not being written. (…
Detecting Crashes in Multi-Threaded Programs
Detecting crashes in multi-threaded systems can be difficult. Often the crashes are difficult to reproduce, and when they happen the faulty operation could have happened many calls ago and so the you don’t get a stack trace at the time…
Get USB Drive Serial Number on Windows in C++
Getting the serial number of a USB device in Windows is a lot harder than it should be. ( But it’s a lot easier than getting the USB serial number on Os X!) It is relatively simple to get USB…
Implementing Portable Threads and Mutexes
Implementing a portable framework for multi-threading doesn’t have to be difficult or error prone. With the right framework, implementing multi-threaded programs can be pretty simple, and you can hide all the platform dependent functions. You can also implement your threading…
Link Errors Compiling MySQL C++ Programs on 64-bit Windows
I’m starting to code up a simple MySql connector class. Here is the code for the class. First the header:
Generate Stack Traces on Crash Portably in C++
There are three basic steps to getting this done, trapping signals, getting the stack frames, and then demangling the c++ symbols. Trapping Signals When a program crashes the operating system will sent it a signal, to give it one last…