[Tutor] Simplistic drive simulation

Alan Gauld alan.gauld at btinternet.com
Sun Mar 13 10:11:50 CET 2011

"R. Alan Monroe" <amonroe at columbus.rr.com> wrote

> I was just going to start with, say, 16 or 64 "blocks", then 
> randomly
> add and delete ficticious "files"

> 1. Is there some more clever way of tracking this than the very 
> naive
> approach:
> toc = {
>  A: [0, 1, 2],
>  D: [3, 4, 5, 9, 10],
>  C: [6, 7, 8]
> } ?

Obviously yes, there is. Just read up on the various types
of filesystems on Wikipedia for examples. What you are
doing is pretty close to the original DOS FAT filesystem
although even it did a bit more than you describe.

But you can add more and more complexity through
FAT2, NTFS, HPFS, and eventually wind up with the highly
complex file systems used on supercomputers like the Cray
and in dedicated Network Storage Arrays such as those
used by EMC etc

> 2. Is there some more clever way of adding files beyond the very 
> naive
> brute force approach (pseudocode):
> block=0
> while file still has more to write:
>      while drive[block]!=none:
>            block += 1
>      drive[block] = file.pop(0)
>      toc[file].append(block)

You can keep tables of contents to map fee disk space in
terms of block cluster size so that you try to write the file
into the smallest contigious chunk into which it will fit.
There are also various algorithms for trweating the blocks
as groups and then slicing the groups into mini groups
as the space gets consumed. Most Operating System
text books contain chapters on file management.

> Neither of these seem like they'd scale very well (say, up to the
> resolution of your screen, with one block per pixel). The end goal 
> is
> just a basic do-nothing light show that simulates
> fragmentation/defragmentation as eye candy.

For that purpose the basic style you are using will be adequate.
You are only talking about 2-5 million pixels at most on
typical monitors. Usually more like 1.5 million on a laptop.
And you are not too worried about speed, in fact too fast a
display would just be wasted as most chanmges would
never be seen!


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list