Monday, July 8, 2024

CST334 - Week 3

 

CST334 – Operating Systems - Week 3

In this week, we are learning about memory in Unix. The two types of memory are stack memory and heap memory. Each type of memory has its own properties. For example, the stack memory is deallocated after the return statement; however, the heap is controlled by the programmer.

Example int *ptr = (int *) malloc(sizeof(int)).

Note: Passing the desired size depends on the declared variable’s data type. This is because sizeof() operator calculation corresponds to the type of data. For example, a terminated null character ‘’\0’ in a string requires adding 1 when strlen() function is used.

The call of free() frees the memory allocated to the heap.

Common issues

  • Not allocating memory – some functions allocate memory automatically
  • Allocate the wrong size or coming short of the size
  • Not initializing memory or initializing memory incorrectly
  • Memory leak when memory freed correctly.
  • Freeing memory too soon or more than once
  • Calling free() incorrectly by passing the wrong pointer

Happy 4th of July!

The hardware-based address translation provides memory access by translating the virtual address to a physical address with the help of the OS. In dynamic relocation or base and bounds, two registers are defining the boundaries of the physical memory. Each process will hold two values, one for the base and another for the bounds while the program is compiled to start at address zero. The OS places the program at a physical address by setting the value of the base then adding it to the virtual address.

The disadvantage of the base and bounds method is the generated wasted physical space after address translation. The segmentation technique helps reduce the unused free memory between the stack and the heap. The OS places different segments of the address space in the physical memory. Also, sharing segments is available to allocate memory efficiently with fewer wasted holes among processes. In the case of context switching, registers are saved and restored to run the switched-to process, preserving the virtual address.




No comments:

Post a Comment

CST462S - Final Week

Service Learning Journal Reflections This marks the final week of our Service Learning experience. Our team successfully completed the final...