Difference between while and do while loop

difference between while and do while loops

In any programming language, whenever we are interested in implementing a single statement multiple times i.e. if we want to type a number for specific number of times or until a specified condition is fulfilled, we do not write the statement that number of times rather we use loops like while,  do-while and for loops. … Read more

Difference between external and internal fragmentation

external fragmententation

The word fragmentation is derived from the word “fragments” which means smaller pieces. Whenever a large chunk is divided into smaller pieces by any means or for any purpose, we call the process “fragmentation”. Fragmentation in computer systems, similarly, is a process of using main memory such that the storage space is used inefficiently and … Read more

Difference between paging and segmentation in operating systems

Comparison charts and difference between paging and segmentation is discussed in this article. Starting with memory management systems and basic introduction of paging and segmentation. What is memory management system?  In operating systems, while we work with different processes, we always come across memory management systems techniques in operating system which are used to manage the memory blocks as efficiently as possible. These techniques are mostly used when we need to work with a large number of processes with a limited memory provided. During the execution of a process the main data (code, stack and heap) of a process is stored in the main memory but due to the restricted size of the main memory we cannot keep all the currently running processes in the main memory so we switch the processes which are not currently running to the hard disk so that we can fetch them back to main memory when it is called by the CPU. Memory management system is used to keep track of the memory (main memory and hard disk memory). It will keep a thorough track of each memory portion, i.e. whether it is allocated to some processes or not and it will allocated each chunk of memory to the newly created process accordingly and update their information in the memory management system accordingly of whether it is occupied or freed. In memory management system, there is a specific portion to understand i.e. whether we are storing the data in memory as large chunks of variable sizes (segmentation) or we are allocating memory to different pages in the form of small fixed sized block (pages).  Let’s have a thorough look on the functionality and uses of each one of them. Introduction to Paging in OS As we have discussed earlier, whenever we want to execute a process in CPU, its data i.e. code, stack and heap must be available in the main memory however only a few of pages are present in the main memory and all other are stored in the hard disk memory (as it has a larger space than main memory), hence for the execution of a page we have to load all the stored data of that page from the hard disk to main memory in order to complete its execution. While loading (or swapping) data from the disk memory to main memory we have to swap a specific amount of memory in some cases. If we load a fixed block of memory from disk to main memory these fixed blocks are then referred as pages and the technique is called paging. The simple paging phenomenon can be explained well in the image given below, Figure 1: Paging Lets’ assume that the block at the left is a single process divided into 4 parts and the block at the right is the physical memory. It is not mandatory to place all the pages in the main memory one after the other we can place then according to the need so that other processes can share the same memory without any issue. The page table (stored in memory management unit) MMU as we have studied previously is used to access the stored pages in future. For instance, in the above figure the page table tells us that the page with page number 3 (logical page number 3) is stored at the physical address of 7 and so on, which is not difficult to read for a person who have taken a course of operating systems. While working with pages we don’t have to store memory contiguously rather we store it in the form of small chunks (pages). We divide the total memory space required by a process into small fixed sized chunks and place them at different locations within the memory provided that their logical or virtual address are contiguous no matter how distant they are placed in physical memory. This paging technique will reduce the effect of external fragmentation however it will increase the effect of internal fragmentation. Lets’ now have a brief look on fragmentation before jumping to segmentation. Fragmentation basics  In normal language the word fragmentation is referred as breaking a state or a large chunk into small fragments. Similarly, in computer sciences, when a memory unit is used inefficiently small chunks of unused memory are created in the overall memory space. Because of which we cannot use these small chunks and a large amount of memory is wasted. This wastage of memory decreases the effectiveness of memory usage. As we can see from figure 1, that the small non-contiguous portion of memory (the gray colored memory blocks) is used and a large portion of memory is wasted (blue colored blocks). This wastage of memory is referred as fragmentation. Fragmentation can be divided into two major types: Internal fragmentation External fragmentation Internal fragmentation This is the type of fragmentation which occurs whenever we have divided memory into fixed sizes of blocks. For instance, the block size in which we have divided the memory is 4Kb and we want to assign memory to a data block of size 3Kb, thus the memory assigned to the data will be a bit larger than the memory requested. This will cause internal fragmentation of 1kb in a single page. This may seem small but on a larger scale even this amount of memory will reduce the memory performance to a significant rate. External fragmentation Now comes, the external fragmentation portion, whenever we load a process in the memory it will create small holes or gaps in memory allocation. External fragmentation occurs when the physical memory has enough space available in it to entertain a whole new process, but it could not do so because the available memory is not present in a contiguous manner. This can occur either by first fit or best fit method. External fragmentation occurs when the memory management strategy used is segmentation rather then paging. We will now divert our attention towards segmentation. But let’s first conclude the fragmentation topic with the help of an image illustration as shown below, Figure 2: Fragmentation As shown in the figure above, internal fragmentation occurs within the same memory chunk and external fragmentation occurs between two different portions of memory. Introduction to Segmentation in OS Segmentation is also one of the techniques to use memory efficiently. When we allocate memory to processes in form of variable sized large portions, this allocation is called as segmentation. The issue with segmentation is that when we allocate a process to memory it will create a hole in that specific portion of memory. Even after we remove the processes from that portion, we cannot allocate the created hole to a process with larger data size. Let’s assume that data is stored in the above memory block through segmentation. We assigned a data block of 1Kb then 3 kb then 8kb and at the end 4kb to the memory and after that we remove the process with size 3kb and 4kb. Now, we want to add data block of size 6kb to memory, although we have available space of 7kb but we cannot assign the given data bloc (7kb) to the memory because the memory availble is non-contiguous. Memory allocation of this type is called segmentation and this flaw in segmentation is called external fragmentation. This issue in segmentation can be resolved with the help of coalescing, which itself is a very long topic of discussion in computer systems. For the time being, accept that coalescing is a scheme of combining the externally fragmented portion of memory that are coincinding with each other in phycial memory. Comparison chart of paging and segmentation  Paging Segmentation Size of block Fixed Variable Type of fragmentation Internal fragmentation External fragmentation Basic Fixed size of data is retrieved from disk to main memory Variable size of data is retrieved depending on the size of process data Table A page table is involved which contains the page numbers mapped with physical address A segment table is used which contains the segment number mapped with physical address Address Address is divided in page number and offset Address is divided in segment number and offset You may also like to read:  Difference between preemptive and non-preemptive scheduling in Operating systems Difference between logical and physical address in Operating Systems

Comparison charts and difference between paging and segmentation is discussed in this article. Starting with memory management systems and basic introduction of paging and segmentation. Recommended Books Books that cover this topic in more depth. Book Why read it Buy on Amazon Operating System Concepts (Silberschatz) The standard operating systems textbook: processes, scheduling, memory and … Read more

Difference between preemptive and non-preemptive scheduling in Operating systems

Preemptive scheduling

Before jumping onto the differences between preemptive and non-preemptive scheduling in operating system directly lets’ first have an overview about what scheduling means in operating system.What are the important terms used to define scheduling of tasks and processes in operating systems. First, We will define preemptive and non-preemptive scheduling and at the end, we will … Read more

Difference between Mainframes and Mini Computers

Mainframe and Mini Computer

Mainframe and Mini computers are two different types of machines designed to perform computations for different requirements. By reading about difference of Mainframe and MiniComputer, you will able to compare them. A computer is a machine that is programmable. Information is received by it in the form of digital data and then it processes the … Read more

Create Simple ESP8266 NodeMCU Web server in Arduino IDE

ESP8266 Web server NodeMCU in Arduino IDE

This guide teaches you how to create a simple ESP8266 NodeMCU web server in Arduino IDE. You will learn to control GPIO pins of ESP8266 NodeMCU from a basic Web server. You also get to know about creating password protected web server with ESP8266 based NodeMCU board. Although, you can use this tutorial for any … Read more

LED Blinking using ESP8266 – NodeMCU

ESP8266 LED Blinking Circuit Nodemcu

We all familiar with blinking LED using Arduino boards as this is the fundamental step towards using a new development board. In this tutorial, we are going to learn basic built-in commands of Arduino IDE which will help to blink LED using ESP8266 NodeMCU and ESP-01 module. If you wonder how to install Arduino IDE … Read more

Reference for ESP8266 using Arduino IDE

Reference ESP8266 using Arduino IDE

Before getting started with the hardware this tutorial is used to understand the fundamentals of Arduino Programming Language and Language reference for ESP8266 for Arduino IDE. If you wonder how to install Arduino IDE for ESP8266 feel free to visit our tutorial on that here. Keep in mind that we are using ESP8266 it is … Read more