I always like to offer notes on interesting projects that I work on at Purdue, if not to aid my own reflection then to share ideas, problems, and solutions. For my Systems Programming class, we were asked to implement a memory allocator in C. I had worked on some components of an Operating System before, implementing a system printf function in the XINU operating system, but this was a massive step up in both scope and relevance. I couldn’t wait to dig in.
Obviously, my implementation was going to be nowhere near as thorough and heavily tested as the real thing, but the fundamentals of it were quite revealing. Aside from becoming intimately re-familiarized with manipulating pointers, this biggest thing I came away with has to be just how conceptually simple yet fragile free and malloc are.
The intricacies of the process was at times overwhelming. For allocating, traversing the linked list for an appropriately sized memory block, properly sizing the headers and footers of memory blocks, and splitting and returning excess memory to the free list when necessary was conceptually simple but at times difficult in implementation. Freeing memory and coalising neighboring memory blocks when necessary really underlined just how fragile the methods used for malloc / free, as with every error I became even more sympathetic to those behind all the blue screen of deaths I experienced growing up.
Nonetheless, this project was a lot of fun as it was both challenging and also readily relevant. Certainly, this project contributed greatly to widening the distribution of the timestamps of my GitHub commits, but I can’t wait to see what we cover next.