As Total Commander quickly opens a folder?

Windows specific questions.
VANYA
Posts: 1465
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

As Total Commander quickly opens a folder?

Postby VANYA » Jun 07, 2011 12:51

As Total Commander quickly opens a folder? When iterating through FindFirstFile - FindNextFile very long obtained in folders on the 3000 - 4000 files. If you point to examples, I would be grateful.
AMIBCT
Posts: 53
Joined: Jan 14, 2008 8:48
Location: Tehran
Contact:

Postby AMIBCT » Jun 07, 2011 18:03

FindFirst and FindNext are fast enough to search folders

Incorrectly manipulating 3000 or 4000 files can slow down your GUI.

Listing ~30,000 files while CACHED takes less than one second using FindFirst and FindNext...

Look this spaghetti implementation of folder search:

http://amib.ir/downloads/FolderSearch_FB.zip

http://www.freebasic.net/forum/viewtopic.php?p=91093
VANYA
Posts: 1465
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Postby VANYA » Jun 07, 2011 18:24

AMIBCT wrote:FindFirst and FindNext are fast enough to search folders

Incorrectly manipulating 3000 or 4000 files can slow down your GUI.

Listing ~30,000 files while CACHED takes less than one second using FindFirst and FindNext...

Look this spaghetti implementation of folder search:

http://amib.ir/downloads/FolderSearch_FB.zip

http://www.freebasic.net/forum/viewtopic.php?p=91093


Thank you, I look
VANYA
Posts: 1465
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Postby VANYA » Jun 07, 2011 19:09

Соглашаюсь FindFirst работает быстро, но если заносить в ListView то при 3000 файлов 2-3 секунды. А в Total мгновенно! Какие там методы, подскажите пожалуйста?

Agree FindFirst is fast, but if you bring in the ListView then 3000 files 2-3 seconds. And in Total Commander or Explorer instantly! What methods are there, tell me please?
dkl
Site Admin
Posts: 3221
Joined: Jul 28, 2005 14:45
Location: Germany

Postby dkl » Jun 08, 2011 20:41

I think maybe Explorer is remembering (caching) the tree of files/directories, so it doesn't have to re-read them all the time you switch folders in the Explorer window. I know that you can use F5 to refresh/reload the tree, but Explorer also does automatic updates, maybe with something like FindFirstChangeNotification & others. That caching and refreshing behavior is definitely necessary for directories from computers from a network.

Besides that I think that the Explorer (or whatever is responsible for it) already reads in and caches directories at system start up, for example the Desktop, so that may explain why it can show directories so fast even when you just opened them for the first time.

Or maybe it just has a very close connection to the file system, I don't know.

The list view in the GUI is a different problem, maybe it only shows as much as fits on screen, or has a certain limit (but still adjusts the scrollbar as needed). It would be pointless to load 3000 files into it if you can only see 100 at a time on your screen. Of course it's also possible that they're using a customized or completely custom list view control.

And I'd expect it all to be multi-threaded, so the GUI doesn't hang or freeze.
St_W
Posts: 1514
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Postby St_W » Jun 08, 2011 22:46

The ListView Control is quite slow - maybe that's your problem.

Try using a virtual ListView. A virtual listbox only knows how many items it contains in total and the items it needs to display. So you can display thousands or millions of items in your ListView.

See http://msdn.microsoft.com/en-us/library ... 85%29.aspx ("Virtual List-View Style") for further reference.
VANYA
Posts: 1465
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Postby VANYA » Jun 09, 2011 3:38

Yes indeed the rate is low because of the ListView.

Try using a virtual ListView.



This I need!!


Thank you very much for your answers
St_W
Posts: 1514
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Postby St_W » Jun 09, 2011 14:42

Today I looked how Windows Explorer (Win XP SP3) solves this problem. It does *not* use a virtual ListView. As I read further on MSDN some features of the ListView aren't available when using virtual ListViews. Such a feature is e.g. grouping.

Maybe that paragraph from MSDN (link posted in my previous answer) could be the solution:
MSDN wrote:To add an item to a list-view control, use the LVM_INSERTITEM message, specifying the address of an LVITEM structure. Before adding multiple items, you can send the control an LVM_SETITEMCOUNT message, specifying the number of items the control will ultimately contain. This message enables the list-view control to reallocate its internal data structures only once rather than every time you add an item. You can determine the number of items in a list-view control by using the LVM_GETITEMCOUNT message. If you are adding a large number of items to a list-view control, you can speed up the process by disabling redrawing before adding the items, then enable redrawing after the items are added. Use the WM_SETREDRAW message to enable and disable redrawing.

Windows Explorer does exactly this when refreshing folder contents.

First it deletes all items using LVM_DELETEALLITEMS
Then it disables redrawing the ListView each time by sending a WM_SETREDRAW message.
Afterwards it inserts the items using LVM_INSERTITEMW. If you know how much items you will insert it may be a good idea to send a LVM_SETITEMCOUNT message before inserting items (Explorer doesn't do that).
Finally it enableds redrawing again by sending a WM_SETREDRAW message.
Loe
Posts: 323
Joined: Apr 30, 2006 14:49

Postby Loe » Jun 10, 2011 7:16

To avoid GUI choked when adding large number item in listview in an event (eg buttonclick). Im using Multithread. Place Dir listing and listview add item code in separate thread

Code: Select all

function IDD_DLG1_btFind_Clicked(Byval hWin as hwnd,Byval hCtrl as lparam)as long
   If busy Then Return 0
   pthrd=ThreadCreate(Cast(Any Ptr,@ff),hwin)   
   function=true
end function


ff is a dirlisting code itself

edit
oops dkl already mentioned that
VANYA
Posts: 1465
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Postby VANYA » Jun 10, 2011 9:14

Loe wrote:To avoid GUI choked when adding large number item in listview in an event (eg buttonclick). Im using Multithread. Place Dir listing and listview add item code in separate thread

Code: Select all

function IDD_DLG1_btFind_Clicked(Byval hWin as hwnd,Byval hCtrl as lparam)as long
   If busy Then Return 0
   pthrd=ThreadCreate(Cast(Any Ptr,@ff),hwin)   
   function=true
end function


ff is a dirlisting code itself

edit
oops dkl already mentioned that


Thank you very much, but I already tried that. With this method we can not guarantee that everything will be stable during the rapid transition from folder to folder. I am on a day lost, but the result bad :(
The best probably is that the proposed St_W
Loe
Posts: 323
Joined: Apr 30, 2006 14:49

Postby Loe » Jun 10, 2011 9:50

With this method we can not guarantee that
everything will be stable during the rapid transition from folder to folder.

you can use 'semaphore' and thread procedure should watch this semaphore to FORCE-EXIT the thread when you have to rapid move from folder to folder

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 5 guests