[gtkmm] saving a TreeView to disk



I have a program which parses a large directory structure into a tree view. There are several hundred directories to scan for, though, and it's pretty slow. Since the directories don't change very often (just the files within them), I was thinking about saving the tree on disk, and reloading it in when the program starts up.

Taking the treeview example in the docs, I thought perhaps I could save the contents of ( Glib::RefPtr<Gtk::TreeStore> ) m_refTreeModel as a binary file, then load it in again - I think this is all that I'd need to recreate the tree. Would this work? I'm not entirely certain how to do it either; get a pointer to the start of the tree store, find the total size of it and do an fwrite kind of thing (which assumes the tree's in contiguous memory)? or would i need to iterate over the whole tree, saving each row in some fashion?

I realise I could store on disk some kind of textual structure representing the tree, and recreate the tree from that on startup, but I'm hoping for a more simple solution!



bevis


PS alternatively, does anyone have a code snippet for recursively scanning directories really quickly? currently i'm using something like:

 DIR *dirp = opendir(dirname);
 while ((dirent *dp = readdir(dirp)) != NULL) {
   temp = dirname+"/"+dp->d_name;
   stat(temp, &sbuf);
   int isdir = sbuf.st_mode & S_IFDIR;
   if (!isdir)
     continue;
   ... put in tree ...
   ... recurse ...
 }

but it's over NFS so that may be the bottleneck.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]