Contiguous allocation is a file allocation method where each file occupies a contiguous block of physical storage space, ensuring data is stored sequentially.
Mind Map
Click to expand
Click to explore the full interactive mind map • Zoom, pan, and navigate
- Hello friends, Welcome to Gate Smashers.
- In this video I'm going to explain contiguous allocation.
- And we will discuss all the important points related to contiguous allocation.
- that will be helpful in your competitive exams and even in your college and university exams.
- so guys like the video and subscribe the channel if you haven't done it yet. Please press the bell button so that you can get all the latest notifications.
- Let's start with contiguous allocation.
- As the name suggests, that we're allocating memory in continuous to the blocks of our file.
- Means, the storage we have, we are placing the data in continuous way in the storage
- there's a simple example, like, we often tell students to sit roll number wise in class
- so obviously what happens there, let say roll no.1 sat on bench no.1, roll no.2 on bench no.2, roll no.3 on bench no.3, roll no.4 on bench no.4
- so it is allocated in contiguous way.
- so obviously it is not necessary that roll no.1 must be sitting on bench no.1, wherever it will start
- obviously, we'll keep the next bench for the next roll no.
- so this is the simple concept of contiguous allocation
- so let me explain you by a simple example, let say we have 3 files A, B and C
- It is directory
- what is the actual use of directory, why we use directory, because directory contains all the information, all the information related to files.
- so here I've taken only 3 information’s, Name of file, where the file starts from and what is the length of the file.
- Means, what we've done, let say we have a file, File A , So what we have done , We divided that file A
- in 3 parts i.e. part 1, part 2, part 3
- so obviously it becomes block 1, block 2 and block 3
- so this is the actual meaning of length. So actually we understand by length that how much blocks it acquires in memory/storage.
- how much physical block it will acquire. Similarly, we've file B, we've divided that into 5 parts.
- we've file C, we have divided that into 4 parts.
- because what we do to the data
- it may be like the size of the sector is small and the file is very big. Because nowadays we're dealing in gigabytes of data, terabytes of data
- so obviously, the whole file in gigabyte won't be stored as it is
- so we divide it, so that is actually logical division.
- so this directory contains all the information
- So look what we have done, we started file A from block number 0 or you can say from sector number 0
- so what I have, A disk, We have made the disk from inside like, usually we make disk like track/sector
- but here we've made it in simple way. Now see, we have physical sectors inside the disk
- the location, physical location where the data will come. So now what we're doing, we are starting from 0.
- Means we are starting the first block from 0 of file A. So that means, from 0 to 3 of file A
- the meaning of 3 is length 3. So the meaning of length 3 is that the first is placed at 0, second is placed on 1 and third is placed on 2.
- So this is actually length 3. So the meaning of length 3 is that there are 3 blocks of file A.
- So I've placed first block at 0, so where will I place the second block, obviously the next location is 1.
- Where will I place the third block, obviously the next location is 2.
- that is the meaning of the contiguous. You have to place it contiguously not like randomly anywhere.
- Similarly, look at file B. We're starting file B from 6.
- so here is my six no. block. Now how many, we've divided it into 5 blocks.
- so obviously you can say, we started from 6, so, 1, 2, 3, 4, 5
- So look, we have stored file B from 6 to 10
- Similarly file C, we are starting file C from 14 and we are dividing it into 4 blocks that means physically it will take 4 blocks
- So start from 14. 1, 2, 3, 4. So we placed the data contiguously like this.
- so this is the simple meaning of contiguous allocation.
- Now let's talk about what the advantages and disadvantages
- because a lot of questions are asked like this. They're of very simple level
- but many times, if you don't know the concept then you won't be able to visualise it easily
- that what is actually happening. So look, the first advantage is 'Easy To Implement'
- this method is easy to implement because we use pointers in other methods
- we place data randomly so there we have to use pointers or in index one we have to make extra index
- so there neither we are using pointers not we are making index. We simply said that start from 0
- put the data contiguously according to length
- Next, excellent read performance. This is a very important part.
- Either we are doing sequential access or we are doing direct access, these both methods are easy to access
- Why? What's the reason of this? You know from this now that
- I've to read the data. So look, at the time of reading, sequential
- Sequential means, let say I have to read 6, 7, 8, 9, 10, all. So actually what happens in a disk
- let say this is my one track, now in this track let say here is the 6 number. So we entered the data in 6
- The next block is on 7, the next, on 8 and the next to it, on 9 and the next to it on 10
- because we placed from 6 to 10. So we allocated this sectors contiguously.
- Now see, when our read write hand will reach here that means when read write hand will reach the particular track where the data is lying actually
- so it took 1 seek time, and from that seek time
- What is seek time? It is the time taken to reach the desired track. So it reached on desired track
- now after reaching the desired track, it has to do nothing, simply just rotate the disk
- and after rotating you get all the data 6, 7, 8, 9, 10
- and if you would have placed the data randomly, let say you placed 6 here, and next block in another track, and next in another track
- then obviously you've to change track again and again. And as often you change the track seek time will increase accordingly
- so because of that our access will increase. So that's why, in order not to increase access time
- what we did, we placed the data sequentially. So, as soon as we reached the particular track
- just rotate the disk and you'll retrieve all the data. So this example, actually this is the advantage
- read performance is excellent in case of contiguous. And the meaning of direct is that, Let say, 9th
- You don't have to access the whole file, you just have to access the 9th no. block of the file. So it's easy in this case also, because you get to 6
- and after that you know obviously it is placed contiguously. That means, like you entered in the class and you know students are sitting contiguously in class
- And you, let say, you have to go to roll no. 10. So to get to 10, and obviously if you are standing at roll no.1
- then obviously you know that he must be sitting after 10 benches because roll no.1 is on bench no.1, roll no.2 on bench no.2, 3, 4, 5
- So it's not like you have to search randomly. You reached at one place, like you reached on 6 now you know that 9 must be after 3 locations
- So, 7, 8, 9. You'll get 9 after three. So either you do direct access or sequential, even if you access the whole file
- your access time will be less or you can say access speed will be faster. So this is the main advantage of the contiguous allocation.
- Now let's talk about disadvantage. So the disadvantage here is
- the first disadvantage is fragmentation. Fragmentation generally happens in two ways, internal fragmentation and external fragmentation
- Actually internal fragmentation is, let say, that your block, one physical block
- that data we have, the size of a physical block inside a disk, let say, 5 kb, I'm just taking a simple example
- 5 kb is the size of a disk block and the block of your file, let say it's size is 3 kb. So you entered 3 kb data there
- then the 2 kb space which is remaining will not be utilised. So obviously this is called internal fragmentation. So there is no solution of internal fragmentation
- internal fragmentation can occur everywhere but the major problem here, that is a external fragmentation
- because the internal fragmentation, if the file size is low so obviously what can we do in that case, nothing. But external fragmentation is quite popular here
- What is the meaning of external fragmentation, it has a simple meaning, look, now you have placed the block here, let say, you placed 1, 2, 3, have also put this, have also put this
- now you know you have, let say, 3, 4, 5 these three. You have these three empty. And let say after that this one is empty and these three are empty.
- now see, let's suppose we don't have any after that, means that's all we have in a block. Now a new file enters, D.
- D file enters and D file wants, let say, 4 block. It needs 4 block that means it's total length is 4 block.
- So look, although how many block you have empty, 1, 2, 3, 4, 5, 6
- You have 6 empty blocks, it's clearly visible. Here it is, 1, 2, 3, 4, 5, 6
- But the problem is these 6 are not contiguous. First you have 3 empty, then there's data, then 1 is empty, then 2 are empty and then there's data.
- what it meant to say is that you have 6 blocks empty, then if 6 blocks are empty so if a file demands of 4 blocks or 5 blocks then you have to place that
- but you can't place them. Reason behind that is that this is contiguous. You can't do that you placed 3 blocks here and 1 block there out of 4 blocks, No.
- Because it is contiguous allocation. It want the 4 blocks collectively.
- So that is called the external fragmentation. Means, you have available space but you can't enter the data because of contiguous.
- So this is a major disadvantage of the contiguous allocation
- further, that is removed by linked list of index but it is the main purpose here.
- Second, difficult to grow the file. What we're doing in this, we already told
- let say, file A enters, we placed it in 0, 1, 2. After that, let say, another file enters, E, and we started it from 3
- just for example, from 3. And let say we provided it 3 blocks too. That means it is placed here easily, here, here and here.
- Means it is filled. Let say, file A demands, which was in 0, 1, 2.
- it demands of some more space. We added something to it. Like normally we make edits in files.
- We edited the file and it's size increased. Now if the file size increased I cannot provide space to the data
- why I can't do that? Because the next location is full. The next location is filled.
- Now, however, the space is available but it is not contiguous, it is far away somewhere. So I cannot grow the file now.
- Means, I already mentioned, that A file needs 3 block, B needs 5 blocks, C needs 4 blocks, but if they grow
- it becomes difficult as if the space is available contiguously then you can place but if fhe space isn't available it will not allow it to grow.
- but if this was random, then let say, you placed 3 here, and if it demands of 1 more blocks, so if it wants 1 more block then ok take this block
- but you can't provide it here because it needs data contiguously.
- So it becomes difficult to grow the file, to increase it's size or to edit and add something in it
- and second, specially external fragmentation
- although internal fragmentation is also present but that will be present in all cases. Internal fragmentation don't have any particular solution. - So these are the major important points related to the contiguous allocation, Thank You.
- That obviously if your file size is low then what can you do
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.