Page 1 of 1
Memory management functions for secondary storage..
Posted: Mon Jun 27, 2011 9:50 am
by mahmoudaladawi
Hi there,
I just want to hear from you about an idea came to me before starting implementing it..
I just want to use the same algorithms, functions, .. of memory management for secondary storage..
I use bitmap based memory management (the most easy and the less efficient
.) Can't I a bitmap for harddisk storage and just use the same function I've already made?
That will be just for beginning, I will, of course, make an efficient file system later.. But I need filing get done these days..
Thanks in advance
Re: Memory management functions for secondary storage..
Posted: Mon Jun 27, 2011 10:28 am
by mahmoudaladawi
@berkus: Thanks.
Re: Memory management functions for secondary storage..
Posted: Mon Jun 27, 2011 11:33 am
by DavidCooper
You can do a lot better than that for very little effort. For floppy disk storage I use a bytemap with each byte linking to a sector, so I can save 255 different files to a disk just by giving each file a different byte value and putting the value for a file in all the bytes which map to sectors containing that file's data. You could do the same for a hard disk using two bytes each time instead of one, thereby allowing up to 65535 files to be stored on it without needing complicated code to load and save them. Later on you can write some code to defrag your files and convert the directory to a standard format.
Re: Memory management functions for secondary storage..
Posted: Mon Jun 27, 2011 11:50 am
by mahmoudaladawi
@DavidCooper: NiceIdea, but won't that consume enormous amount of memory..? even we did that for block consisting of more than a sector.
Thanks.
Re: Memory management functions for secondary storage..
Posted: Mon Jun 27, 2011 11:54 am
by DavidCooper
Process it in chunks. You only need to load as much of the directory necessary to find enough free pairs of 0 bytes to save your file. For loading files back in from disk you could save time by using a simple trick - cut the maximum number of files in half and use the most significant bit to indicate the final sector of a file so that you know that it's all been loaded once you've got that far.
Edit: You could also keep a list of the first sector number for each file so that you can jump straight to the first sector every time, and also store the sector number of the first empty sector somewhere. Later on you can add a filename list too (stored in filenumber order and with fixed-length names), increasing the functionality of the system whenever accessing your files gets sufficiently difficult to motivate you to get round to doing it.