Howto: Preallocate a File for Faster Writing

Because of how Microsoft's FAT file system works, host systems need to extend files frequently when adding more data, and this means that when a cluster boundary is reached, a new cluster needs to be found and added to the file cluster chain.

Complicated? Not really, but it does cause timing problems when using a microcontroller to stream data to an SD/MMC card.

How do we get around the cluster allocation timing problems?

We preallocate the file - that is, we extend the file at the before we begin writing data to it.

Here is how we do it.

(Note: The command examples are for the uMMC - just add “FC” to the beginning of the command for the rMP3 and uMP3)

  1. Create your file:
    • e.g. “O 1 RW datafile.txt”
  2. Now extend it well beyond what you'll need to write:
    • e.g. “J 1 100000” - this will pre-allocate 100,000 bytes to the file.
  3. Now jump back to the start:
    • e.g. “J 1 0”
  4. Begin writing loop/procedure:
    • e.g. “W 1 200” (followed by data), rinse, repeat
  5. When you are done, you can truncate the file to the new size:
    • e.g. “U 1” - this deletes ALL data after the current position
You could leave a comment if you were logged in.
  • Bookmark at
  • Bookmark "Howto: Preallocate a File for Faster Writing" at del.icio.us
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Digg
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Google
  • Bookmark "Howto: Preallocate a File for Faster Writing" at StumbleUpon
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Technorati
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Facebook
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Twitter
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Slashdot
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Yahoo! Bookmarks
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Furl
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Reddit
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Ask
  • Bookmark "Howto: Preallocate a File for Faster Writing" at BlinkList
  • Bookmark "Howto: Preallocate a File for Faster Writing" at blogmarks
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Ma.gnolia
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Netscape
  • Bookmark "Howto: Preallocate a File for Faster Writing" at ppnow
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Rojo
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Shadows
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Simpy
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Socializer
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Spurl
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Tailrank
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Live Bookmarks
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Wists
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Yahoo! Myweb
  • Bookmark "Howto: Preallocate a File for Faster Writing" at BobrDobr
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Memori
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Faves
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Favorites
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Newsvine
  • Bookmark "Howto: Preallocate a File for Faster Writing" at myAOL
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Fark
  • Bookmark "Howto: Preallocate a File for Faster Writing" at RawSugar
  • Bookmark "Howto: Preallocate a File for Faster Writing" at LinkaGoGo
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Mister Wong
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Wink
  • Bookmark "Howto: Preallocate a File for Faster Writing" at BackFlip
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Diigo
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Segnalo
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Netvouz
  • Bookmark "Howto: Preallocate a File for Faster Writing" at DropJack
  • Bookmark "Howto: Preallocate a File for Faster Writing" at Feed Me Links
  • Bookmark "Howto: Preallocate a File for Faster Writing" at funP
  • Bookmark "Howto: Preallocate a File for Faster Writing" at HEMiDEMi
howto/preallocate_a_file_for_faster_writing.txt · Last modified: 2011/06/09 00:07 by bhagman
Valid CSS Recent changes RSS feed Valid XHTML 1.0