[fpc-pascal] Question on how to avoid memory trouble using FindFirst(), FindNext() and FindClose()

Marc Santhoff M.Santhoff at t-online.de
Sat Feb 3 16:36:56 CET 2007


Am Freitag, den 02.02.2007, 08:52 -0800 schrieb Cox, Stuart TRAN:EX:
> I am trying to EnumerateFiles (create a list of all files that match a
> given filespec) across and down a whole drive.  I've directly used the
> EnumerateFiles code from TurboPower's SysTools as available on
> SourceForge.
> 
> The code works just as TurboPower designed and it and my wrapper code
> runs find on some drives but fails miserably on the very one that I
> would like to use the code on.  As the EnumerateFiles code attempts to
> append one more filename to the Tstrings, it throws an exception and
> dies from lack of memory.  The trouble is not in the memory used by the
> Tstrings to hold the list of found files but, rather, in the way that
> memory fragmentation occurs during the FindFirst(), FindNext() and
> FindClose() calls.  This can be verified by eliminating the storage of
> anything in the Tstrings list at all.  The routine will still die and in
> the same place and at the same filename.
> 
> The error is not from a lack of stack space, either.  The error is
> EOutOfMemory that indicates a less easily solved problem.
> 
> Can anyone recommend a method to search a whole drive, of arbitrary
> size, without running out of memory.

>From reading this thread I think you must have another problem, likely
in TurboPowers or your own implementation.

I've been doing the same (listing deep file systems) and never had any
problems with memory. My classes are made mainly for indexing storage
and backup media (CD, DVD, ...) and I've tested it five minutes ago on
an amount of:

$ wc -l storage.txt
  152811 storage.txt

lines naming a file or directory each. The list class in use is a
derivation of "TFPList" (think it's from "classes") with an new sorting
routine (qsort) attached.

I had some problems with the "FindXxxx"-implementation on *nix-like OS,
but that dealt with symlinks.

Happy bug hunting and memory profiling,
Marc





More information about the fpc-pascal mailing list