Get the latest tech news
Using uninitialized memory for fun and profit (2008)
, March 14, 2008. This is the story of a clever trick that's been around for at least 35 years, in which array values can be left uninitialized and then read during normal operations, yet the code behaves correctly no matter what garbage is sitting in the array.
The sleaziness of uninitialized data access is offset by performance improvements: some important operations change from linear to constant time. To make it fast, Briggs and Torczon add a second array named sparse which maps integers to their indices in dense. Returning to the original exercises, it is trivial to change the set into a vector (or matrix) by making dense an array of index-value pairs instead of just indices.
Or read this on Hacker News