Recently I coded a small utility to search my hard drive and clean out files built by Visual Studio. In essence it removed the contents of any Debug or Release sub folders anywhere. I needed this to be able to quickly copy just the source code of a number of projects for another developer. To do this I decided to queue up the directories to delete as the program found then during search. My top choices on how to hold the list of growing directories during search was either an array or a list.
My tool of choice for coding up quick utilities like this is Visual C++ version 6. And I normally employ the MFC classes because I am most familiar with them. So I had to make a choice between the CStringArray and CStringList classes. Usually I go with CStringList because I know the class member functions by heart. However I decided to determine my needs and use the class that fit those needs the best.
The algorithm was to make use of a queue. Every time I found a directory I wanted to add it to the beginning of the queue. And when the program was ready for more processing, it would take the element from the end of the queue. I decided to go with CStringList as usual. The AddHead() and RemoveTail() operations were just what I needed. RemoveTail() is especially useful because it gives me the element I want and removes it at the same time.
I will confess that performance did not even enter my mind when making a decision on the class to use. But in retrospect, the list may very well be the fastest choice anyway. It should be easier to remove items when all that connects them with the rest of the list are pointers. A brute force implementation of the array would not best well suited to insertions or deletions at one end of the array.
Reproducing a Race Condition
-
We have a job at work that runs every Wednesday night. All of a sudden, it
aborted the last 2 weeks. This caused some critical data to be late. The
main ...