Using uninitialized memory for fun and profit (2008)

In this web content, the author discusses a clever trick that has been used for at least 35 years, which involves leaving array values uninitialized and then reading them during normal operations. This trick allows the code to behave correctly regardless of what garbage is present in the array. The use of uninitialized memory may be controversial, but it offers performance improvements, such as changing certain operations from linear to constant time. The author highlights the work of Aho, Hopcroft, Ullman, Bentley, Briggs, and Torczon who have explored and expanded on this trick in their books and papers. They propose techniques to initialize entries in matrices or vectors to zero the first time they are accessed, reducing initialization time and making operations more efficient. The author explains a specific example of using this trick with a set of integers represented by a bit vector. While iterating over or clearing the set is slow with a bit vector, the trick allows for more efficient operations. Briggs and Torczon’s paper provides a detailed explanation of the trick, using two arrays to represent the set and allowing for fast set operations. The author also discusses the space cost of this representation, as it requires more memory than a bit vector. However, there are situations where the speed differences outweigh the

https://research.swtch.com/sparse

To top