[Tutor] Simplistic drive simulation

R. Alan Monroe amonroe at columbus.rr.com
Sun Mar 13 07:51:51 CET 2011


I'm trying to mentally plan out the most bare bones drive simulation
possible, but I have this nagging feeling that I'm missing something.
I was just going to start with, say, 16 or 64 "blocks", then randomly
add and delete ficticious "files" (which won't have any actual
content - I'm just trying to do the block management portion). For
instance:
drive=[None * 16]
add 3 files A,B,C
AAABBBCCC.......
delete file B
AAA...CCC.......
add file D
AAADDDCCCDD.....
etc.

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]
} ?

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)

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.

Alan



More information about the Tutor mailing list