> is there a fast way of determining how many files are present on the card?
No
>
> Solving this problem when scanning the main memory is easy - there is just
one non-recursive loop there and I execute one step of it (i.e., one
DmGetNextDatabaseByTypeCreator call) each time I get a nilEvent.
Basically yes, but if you act as a foreground task and the DB processing is
fast, then you should consider processing of multiple databases in one step.
If you write a bkg DB, then you should somehow cope with possible DB changes
while running the loop. (In fact the DB changes are possible in the first
scenario, too. Maybe reacting on respective notifications...)
> Implementing a non-recursive directory tree traversal is a bitch -
basically, I'll have to implement the recursion "manually" by organizing a
stack and saving there the intermediate variables of the function that
returns the next file...
That's easy. If the speed is a factor, then you might find that some
arrangements work better. E.g. opening the files during the enumeration of
the parent directory is much faster than remembering the file paths and
opening them after the directory is closed.
> Is there a more intelligent way to do it? Perhaps something like doing
>
> if (EvtEventAvail ())
> {
> EvtGetEvent (&event, eventTimeout);
> if (! SysHandleEvent (&event))
> MenuHandleEvent (0, &event, &event_error);
> }
>
> inside the loop that enumerates the contents of a directory on the memory
card, so that I can give the OS the chance to process its events while I'm
traversing the directory tree?
Either this or the other way around - calling your enumerator from the main
event loop to do a few steps on each nilEvent.
BTW, selecting EvtEventAvail() or nilEvent processing has some implications:
The former case does not send notifications and is faster.
Best regards,
Jan Slodicka
----- Original Message -----
From: "Dr. Vesselin Bontchev" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[email protected]>
Sent: Wednesday, April 20, 2005 4:17 PM
Subject: Memory card traversal
> Hello folks,
>
> I am at the point where I have to implement examining the contents of
every file on a memory card.
>
> First, a quick question - is there a fast way of determining how many
files are present on the card? For the main memory, we have DmNumDatabases.
I can get the number of files by enumerating recursively the contents of the
card and counting them - but that could be a rather slow operation. Is there
a faster way? Probably not, given that it's just a FAT filesystem, but I
thought I'd ask anyway. :-)
>
> Now, the memory card has a tree-like directory structure, where every
directory (node) can contain files. Normally, traversing a tree-like
structure is a trival task given to first-year computer science students.
:-) Elegant recursive solutions exist and I've done it many times in the
past.
>
> But... this is PalmOS we're talking about here. The recursive traversal of
the directory tree and the examination of every file could be a
time-consumming operation; I can't afford to have the traversal code usurp
the use of the device for such a long time.
>
> Solving this problem when scanning the main memory is easy - there is just
one non-recursive loop there and I execute one step of it (i.e., one
DmGetNextDatabaseByTypeCreator call) each time I get a nilEvent. But how to
do this while scanning the memory card?
>
> Implementing a non-recursive directory tree traversal is a bitch -
basically, I'll have to implement the recursion "manually" by organizing a
stack and saving there the intermediate variables of the function that
returns the next file each time it determines that is has to go down a
directory level.
>
> Is there a more intelligent way to do it? Perhaps something like doing
>
> if (EvtEventAvail ())
> {
> EvtGetEvent (&event, eventTimeout);
> if (! SysHandleEvent (&event))
> MenuHandleEvent (0, &event, &event_error);
> }
>
> inside the loop that enumerates the contents of a directory on the memory
card, so that I can give the OS the chance to process its events while I'm
traversing the directory tree?
>
> Regards,
> Vesselin
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/