-
September 24th, 2009, 12:02 AM
#1
[RESOLVED] Need advice - what to use CStringArray or CStringList
I have a program that first counts and remembers file paths in a specified folder in accordance with a certain filter and then processes them. The counting part of the function needs to collect all file names into an array. The processing part needs to see if a certain file name is in that array.
What type of arrays shall I use for that: CStringArray, CStringList or CStringMap? I'm kind of confused over what each of them does (please don't point me to a Microsoft description, I read it about five times and I still don't get it.) I'm basically looking for the fastest implementation of the dynamic array for this purpose.
-
September 24th, 2009, 12:40 AM
#2
Re: Need advice - what to use CStringArray or CStringList
Are you interested in the fasted insertion or fastest lookup?
-
September 24th, 2009, 12:47 AM
#3
Re: Need advice - what to use CStringArray or CStringList
I'll technically be using both.
-
September 24th, 2009, 02:37 AM
#4
Re: Need advice - what to use CStringArray or CStringList
Victor Nijegorodov
-
September 24th, 2009, 04:29 AM
#5
Re: Need advice - what to use CStringArray or CStringList
Originally Posted by ahmd
I'll technically be using both.
Yes, of course, but which is going to be more important? Once collected, are you going to do lots of look-ups? I would consider using a map in this case.
-
September 24th, 2009, 05:23 AM
#6
Re: Need advice - what to use CStringArray or CStringList
Originally Posted by cilu
Yes, of course, but which is going to be more important? Once collected, are you going to do lots of look-ups? I would consider using a map in this case.
I agree. If you need to do a lot of lookups based on a value, a map would be best.
-
September 24th, 2009, 05:23 AM
#7
Re: Need advice - what to use CStringArray or CStringList
If number of items are only inserted at end, and around 100 elements reside in container, then std::vector is very appropriate. Even with 1000 elements, vector search works faster than maps!
-
September 24th, 2009, 05:47 AM
#8
Re: Need advice - what to use CStringArray or CStringList
I'm searching recursively thru files in a folder (so I can't tell you how many there are -- it may be anything from 0 to 10,000 and more). At this stage I need to collect all the file paths in an array.
When all files are found, the second round of recursive search opens each file and processes it in a certain way. At this point if a certain tag is found in a file, I need to match that tag with a file name in the array created above. Each file, on average, may contain from 0 to 10 of those tags, but that number can be more.
So what would you use in this case? (I can't go with std::vector since I've never used it before and I need to go with something that I already know.)
-
September 24th, 2009, 06:19 AM
#9
Re: Need advice - what to use CStringArray or CStringList
Originally Posted by ahmd
When all files are found, the second round of recursive search opens each file and processes it in a certain way. At this point if a certain tag is found in a file, I need to match that tag with a file name in the array created above. Each file, on average, may contain from 0 to 10 of those tags, but that number can be more.
Could you explain this in more detail ?
1) What is recursive about this search ?
2) What do you ultimately want :
a) for each file ... a list of tags in that file ?
b) for each tag ... a list of files that have that tag ?
-
September 24th, 2009, 07:14 AM
#10
Re: Need advice - what to use CStringArray or CStringList
Originally Posted by ahmd
I'm searching recursively thru files in a folder (so I can't tell you how many there are -- it may be anything from 0 to 10,000 and more). At this stage I need to collect all the file paths in an array.
When all files are found, the second round of recursive search opens each file and processes it in a certain way. At this point if a certain tag is found in a file, I need to match that tag with a file name in the array created above. Each file, on average, may contain from 0 to 10 of those tags, but that number can be more.
So what would you use in this case? (I can't go with std::vector since I've never used it before and I need to go with something that I already know.)
Why a second recursive search? You already have all your file names in your collection object, why not just iterate through that?
-
September 24th, 2009, 07:22 AM
#11
Re: Need advice - what to use CStringArray or CStringList
Just 2 cents...
I hope ahmd refers to a method that searches for all the files in a folder, gets / stores their paths and if a folder is encountered, it calls itself (recursion). So instead of storing only the paths, you can also store the information regarding the parent and the level (starting from 0 for the starting directory). You could just create a class that holds a files path (CString), parent (CString) and level (int) and then create a vector of that class?
BTW, using a vector is very simple...if you are not comfortable with STL, you are better off using CArray provided by MFC or even better if you use CAtlArray, if you do not need the serialization support provided by MFCs CObject.
Bhushan
-
September 24th, 2009, 07:25 AM
#12
Re: Need advice - what to use CStringArray or CStringList
As I said, here is a MFC code to do the find:
You can still get the path, parent and level info and store it in a class and create its MFC Array as I said before...
Bhushan
-
September 24th, 2009, 01:49 PM
#13
Re: Need advice - what to use CStringArray or CStringList
Originally Posted by Philip Nicoletti
1) What is recursive about this search ?
Pretty much what Bhushan showed in his MSDN link -- if I find a folder the function calls itself with it's path.
Originally Posted by Philip Nicoletti
a) for each file ... a list of tags in that file ?
No.
Originally Posted by Philip Nicoletti
b) for each tag ... a list of files that have that tag ?
If I find that the tag matches I'm updating the file that this tag is in and save it back to disc.
Originally Posted by GCDEF
Why a second recursive search? You already have all your file names in your collection object, why not just iterate through that?
Good point. The reason I do this is because it's an option that can be switched off in the program. Without this option being on, I need to count all the files first to display the progress bar during the second pass.
Originally Posted by bhushan1980
So instead of storing only the paths, you can also store the information regarding the parent and the level (starting from 0 for the starting directory). You could just create a class that holds a files path (CString), parent (CString) and level (int) and then create a vector of that class?
I have the code that's already tested and working, rewriting it completely is not what I'm looking for at this point. (Again my goal is to speed it up/optimize it.) But thanks for offering. Truly I didn't think about such approach. Although, wouldn't it be much slower if I propagate the whole class instead of just a CString object?
-
September 24th, 2009, 02:15 PM
#14
Re: Need advice - what to use CStringArray or CStringList
Originally Posted by ahmd
Good point. The reason I do this is because it's an option that can be switched off in the program. Without this option being on, I need to count all the files first to display the progress bar during the second pass.
Okay, but what I'm saying is you can get all the paths from your container for the second pass. No need to go searching the whole directory structure again. That should be high on your list of things to eliminate if you're concerned about performance.
-
September 24th, 2009, 04:08 PM
#15
Re: Need advice - what to use CStringArray or CStringList
Originally Posted by GCDEF
Okay, but what I'm saying is you can get all the paths from your container for the second pass. No need to go searching the whole directory structure again. That should be high on your list of things to eliminate if you're concerned about performance.
Well, not really. I actually started from your approach and what I observed was that once the number of files gets over, lets say, a thousand, it takes longer to collect all file paths in a memory array and then use them from there, than simply doing two file search passes. What happens is that first it goes really fast but then it literally slows down to a crawl (probably due to constant memory reallocations of the dynamic array.) The file search, I believe is cached by the OS so the second pass runs very fast.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|