Your method is great! I am wondering whether I can do some further improvements. I think we can check the size of each set, then we can use the elements in smaller set to find the matched ones in the bigger set (or vice versa?), which can improve the performnace -- but I am not sure about it. Do you have any comments?
I think we can check the size of each set, then we can use the elements in smaller set to find the matched ones in the bigger set (or vice versa?), which can improve the performnace -- but I am not sure about it. Do you have any comments?
Just have your for/while loop check for remaining items in both sets. Something like:
while (there_are_items_in_set1 && there_are_items_in_set2)
"The largest fire starts but with the smallest spark." - David Crow
Your fears that using STL will bloat your program are not well founded. You can check out the source code for set_intersection by looking in the file <algorithm>: it contains a for loop and two if. With STL you only pay for what you use. Note that the algorithm requires the data to be sorted thus you must count the code for the sort algorithm also.
None of the algorithms I used (sort or set_intersection) use or have any need for the C runtime library. There is no distinct C++ runtime library. The only CRT function used is the one I introduced: strcmp (ignoring the functions I used to write the output to the console). None of what you say need be true. In general using STL will decrease your working time and will have not have a detrimental effect on the footprint of your EXE. Most of your fears are superstition.
But in order to use sort or set_intersection, I have to use C++ runtime library. Correct?
This is not the case. Both sort and set_intersection are both just short inline functions with no dependencies on any runtime libraries. Have a look at the algorithm header file. In fact most or STL is like this. These are exceptions such as the stream and locale classes.
To me, it is the same -- since I am trying to remove STL/C++ and implement it by myself. I am looking for an efficient implementation -- there are a couple of sets and each contains a lot of data. Any comments or ideas?
If you really want to re-invent the wheel copy STL's code - all the source is there. After looking at the code in question you'll realise you should have just used it as is. You'll have a hard time matching STL's efficiency.
for mfc, they r almost same. but for atl, they r quite different,and not compatible. I perfer vc7.1, the compiling speed, the compiled file sizes r smaller. and especially, the codes look more perfect than doing it with vc6.
life is like a box of chocolate,you never know what you r going to get.
IMHO, the most cleaner way to exit a thread is simply to return from the thread. For example, if you have a loop within the thread, you can simply use a flag to signalate when the thread must exit. This flag can be set by another thread (by using thread-safe methods, like CCriticalSection).
A thread can be terminated in four ways:
1)The thread function returns. (This is highly recommended.)
2)The thread kills itself by calling the ExitThread function. (Avoid this method.)
3)A thread in the same or in another process calls the TerminateThread function. (Avoid this method.)
4)The process containing the thread terminates. (Avoid this method.)
Option 1 ensures that all thread resources are cleaned up properly. Any and all C++ objects created in your thread function will be destroyed properly via their destructors.
The operating system will properly free the memory used by the thread's stack.
The system will set the thread's exit code (maintained in the thread's kernel object) to your thread function's return value.
The system will decrement the usage count of the thread's kernel object.
Somethings seem HARD to do, until we know how to do them.
Last Visit: 31-Dec-99 18:00 Last Update: 8-Aug-22 4:25