CST334 Week 3
This week I learned how memory is organized and managed within a computer system. One of the key concepts I learned about was the address space, which is divided into sections for the code, stack, and heap with each of these sections is designed for a specific purpose. the code section stores the executable instructions, the stack manages function calls and local variables, and the heap is used for dynamically allocated memory at runtime. I found it interesting to see how these areas are laid out in memory and how their addresses are manipulated so programs can run efficiently.
An important reason to structure memory this way is to virtualize it, which helps protect different parts of the program and ensures that memory is used effectively. Virtualization makes sure each process believes it has access to a continuous block of memory, even though the actual physical memory might be shared with other processes. This design both improves security and prevents conflicts between programs.
Memory allocation itself relies on a clever system for tracking where everything goes. I learned about using a base and bounds approach, where the base marks the starting address of a section, and the bounds indicate its size. This allows the operating system to monitor which parts of memory are in use. Another interesting technique is encoding information in the first two digits of an address to flag where that memory belongs. For example 00 is the code section, 01 for the heap, and 11 for the stack. This makes it easier to quickly determine what region an address points to.
I also learned different memory allocation strategies, such as first fit, best fit, worst fit, and next fit. First fit and next fit are faster because they don’t spend time scanning every possible hole, but they can cause fragmentation over time as they are more likely to leave gaps. In contrast, best fit and worst fit tend to use space more efficiently by reducing small leftover gaps, though they take longer to search.
Finally, during the programming assignment, I learned how memory allocation functions work in practice. It was interesting to see how addresses are calculated and how things like splitting nodes and joining nodes back into contagious space works. This week gave me a great appreciation for how carefully designed and sophisticated memory management is.
Comments
Post a Comment