Memory Management
In the previous chapter, I explained a few things with a lot of hand-waving. I was talking about memory being allocated but I never told you what that actually means. Now is the time to fill in the missing pieces.
Memory management is part of practically every computing system. Multiple programs must coexist inside a limited memory space, and that can only be possible if the operating system is taking care of it. When a program needs some memory—for example, to create an object—it can ask the operating system and it will give it a slice of shared memory. When an object is not needed anymore, that memory can be returned to the loving care of the operating system.
Slicing and dicing memory straight from the operating system is a relatively slow operation. In lots of cases, a memory system also doesn’t know how to return small chunks of memory. For example, if you call Windows’ VirtualAlloc
function to get 20 bytes of memory, it will...