I noticed that the DIR command when using it to search for all files in a directory becomes extremly slow. With a little over 1000 files it could take a couple of minutes to complete. When trying to figure out whats wrong I realized that the 'FindRootDirEntry' function always starts by reading in the FAT start sector and then works it way down to the desired next file (obviously using the 'dirnext' parameter). Reading a sector is slow. The file struct contains two variables (File.FileEntryDirectorySector and File.FileEntryDirectorySectorPos) which keep the last searched sector and position. Using that I replaced the original command in 'FindRootDirEntry':
SectorInitRead(File.CurrentSector) // Read sector to buffer
File.CurrentSectorPos = $000
with
If Repeated = false Then
SectorInitRead(File.CurrentSector) // Read sector to buffer
File.CurrentSectorPos = $000
Else
File.CurrentSector = File.FileEntryDirectorySector
File.CurrentSectorPos = File.FileEntryDirectorySectorPos
Inc(File.CurrentSectorPos,32)
If File.CurrentSectorPos = 512 Then
Inc(File.CurrentSector)
SectorInitRead(File.CurrentSector) // Read sector to buffer
File.CurrentSectorPos = $000
EndIf
RootDirFileNum = Disk.FileSearchNumber - 1
EndIf
Repeated is a Public boolean which I set to true if I am searching through a directory for all files. So essentially, I search the current FAT sector to the end. The existing routine keeps track of the currentsectorpos and loads a new sector only when its required.
There might be a better way, but it works now VERY fast. Searching through a directory with ~ 1200 files takes now less than 2 seconds in contrast to the original couple of minutes.
I also modified the routine that it will return the size of a file without the requirement to open the file first.
I thought that maybe somebody might be interested in that.
Finally, let me state that this is a great module which I use a lot.
Cheers, Michael
SDFileSystem 4.0.9 Dir command
Moderators: David Barker, Jerry Messina
-
- Swordfish Developer
- Posts: 1486
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: SDFileSystem 4.0.9 Dir command
Thanks for that.
Could you post those changes too?I also modified the routine that it will return the size of a file without the requirement to open the file first
- David Barker
- Swordfish Developer
- Posts: 1216
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
Re: SDFileSystem 4.0.9 Dir command
Thanks for posting these changes. They look like they could be really useful. If you email me the new, modified library, I could post on the wiki for others to share..
- David Barker
- Swordfish Developer
- Posts: 1216
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
Re: SDFileSystem 4.0.9 Dir command
I've posted the file here:
http://www.sfcompiler.co.uk/wiki/pmwiki ... ardLibrary
Thanks again for sharing...
http://www.sfcompiler.co.uk/wiki/pmwiki ... ardLibrary
Thanks again for sharing...