Monday, April 18, 2011

Malloc, Free, and the Mall of New Athens

Malloc and Free are commands in the C programming language that are used for dynamic memory allocation. Malloc allocates a block memory of a given size (passed in as an argument) and returns a pointer to that memory. Free takes in a pointer to a block of memory and releases that memory. While this level of memory management is often hidden in many modern programming languages, understanding it can provide valuable insights into how computer memory works.

In ancient times, the mall of New Athens served eighteen different neighboring kingdoms with a combined population of millions. The mall itself was an engineering marvel. It was designed by the the famous architect Hans Lloyd Wright IV. It had the first known three story eatery and the third known use of stained-glass skylights. Visitors would gasp in awe at the sheer number of shops and miles of kiosks. A shopper could find any item they were looking for in at least six different stores.

Even the parking lot itself was hundreds of years more advanced than any other civilization. It introduced an entirely new approach to parking lots: dynamic, coordinated parking. The system was devised by two entrepreneurial brothers: M'Alloc and F'Ree. They had first conceived of the dynamic parking allocation system after spending seventeen hours searching for a parking space in Alexandria. Frustrated, they eventually drove their horses home, vowing to never let this happen in their own town.

The coordinated parking system itself was relatively simple. It was based on centralized coordination with the brothers. The two brothers sat in a small, but surprisingly comfortable, kiosk at the parking lot's only entrance and exit. One brother sat facing a window toward the entrance and the other sat facing the exit. Between them was a giant map of every parking space around the mall.

Upon entry, visitors would pull their horses, carts, double-carts, or long-cart-trains up to the entry attendant M'Alloc's window. M'Alloc would consult the master map, find them spaces in which to park, and hand them a small blue stone token. The token would list the starting slot number where they could park. Horses needed one slot, carts needed three slots and double carts needed five. If there was an appropriately-sized, open space for you to park, M'Alloc would know about it and direct you there. He would also mark off the appropriate spaces as occupied, so that he would not accidentally send someone else there.

Shoppers would keep their small blue tokens while they shopped. If they ever needed to go put bags in their car, they would consult the token and know where they had parked. But if a shopper lost their token, they were in trouble. With nearly two million parking slots it took a lot of walking to find your cart. It is said that, it took one unfortunate shopper two years of checking different slots in order to locate his cart after he had made the blunder of mistaking his parking token for a piece of hard candy.

And on the way out of the mall, shoppers would return their token to the exit attendant F'Ree. F'Ree would mark the corresponding slots on the master map as open. He would smile, wish you a good day, and help point you to the freeway.

It was a great system. However, like all great systems, it relied on a certain level of competency among the shoppers. If a shopper lost a token, they had to slog through the entire parking lot looking for their carts. And without a token F'Ree refused to cross that space off the master map, so it would be marked "occupied" forever. In fact, after five years of operation there were over a thousand "wasted" spaces due to lazy shoppers losing tokens. It was a sore subject with the brothers.

Despite the downsides, the parking lot was a monumental achievement. It handled millions of shoppers coming in and leaving every week. Not until the opening of the Manhattan Mega Mall, which itself encompassed the entire island of Manhattan, would another parking lot even start to compete with its scale or efficiency.


  1. Oddly enough, you could show up without a cart, but claim you had one. You'd then be given a token, and could go to the parking space. Sometimes you'd find a cart, but often as not you'd find a horse. If you tried to ride the horse, odds are it would probably explode.

  2. Of course you could also lie about how long your cart train was. If you said it was only 10 spaces long when it was actually 11, you risk crushing someone elses horse with your back wheels, or coming back to find someone's horse has crushed your back cart.


Note: Only a member of this blog may post a comment.