memorymanagement - Chapter 5 Memory Management Primary...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 5 Memory Management Primary memory is a prime resource in computer systems. Its management is an important function of operating systems. However, in this area the operating system depends heavily on hardware support, and the policies and data structures that are used are dictated by the support that is available. Actually, three players are involved in handling memory. The first is the compiler, which structures the address space of an application. The second is the operating system, which maps the compiler’s structures onto the hardware. The third is the hardware itself, which performs the actual accesses to memory locations. 5.1 Mapping Memory Addresses Let us first review what the memory is used for: it contains the context of processes. This is typically divided into several segments or regions. Different parts of the address space have different uses The address space is typically composed of regions with the following functionalities: Text segment — this is the code, or machine instructions, of the application being executed, as created by the compiler. It is commonly flagged as read-only, so that programs cannot modify their code during execution. This allows such memory to be shared among a number of processes that all execute the same program (e.g. multiple instances of a text editor). Data segment — This usually contains predefined data structures, possibly initial- ized before the program starts execution. Again, this is created by the compiler. Heap — this is an area in memory used as a pool for dynamic memory allocation. This is useful in applications that create data structures dynamically, as is common in object-oriented programming. In C, such memory is acquired using the malloc 99
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
library routine. The implementation of malloc , in turn, makes requests to the operating system in order to enlarge the heap as needed. In Unix, this is done with the brk system call. Stack — this is the area in memory used to store the execution frames of functions called by the program. Such frames contain stored register values and space for local variables. Storing and loading registers is done by the hardware as part of the instructions to call a function and return from it. Again, this region is enlarged at runtime as needed. In some systems, there may be more than one instance of each of these regions. For example, when a process includes multiple threads, each will have a separate stack. In addition, the data and heap may each be composed of several independent seg- ments that are acquired at different times along the execution of the application. In some systems it is also possible to share individual segments of memory in different ways among a number of processes. These different parts have to be mapped to addresses The sum of the sizes of the memory regions used by a process is typically much smaller than the total number of addresses it can generate. For example, in a 32-bit architec- ture, a process can generate addresses ranging from 0 to 2 32 1 = 4294967295 , which
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern