Click here to Skip to main content
16,006,766 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: STL vs. MFC Pin
lpvoid7-Jan-03 2:49
lpvoid7-Jan-03 2:49 
GeneralRe: STL vs. MFC Pin
Christian Graus7-Jan-03 9:37
protectorChristian Graus7-Jan-03 9:37 
GeneralRe: STL vs. MFC Pin
lpvoid8-Jan-03 1:54
lpvoid8-Jan-03 1:54 
GeneralRe: STL vs. MFC Pin
Tim Smith6-Jan-03 10:09
Tim Smith6-Jan-03 10:09 
GeneralRe: STL vs. MFC Pin
User 98858-Jan-03 9:47
User 98858-Jan-03 9:47 
GeneralRe: STL vs. MFC Pin
Christian Graus8-Jan-03 10:01
protectorChristian Graus8-Jan-03 10:01 
GeneralRe: STL vs. MFC Pin
User 98858-Jan-03 10:11
User 98858-Jan-03 10:11 
GeneralRe: STL vs. MFC Pin
lpvoid10-Jan-03 4:44
lpvoid10-Jan-03 4:44 
Christian,

The tests I performed were indeed unlikely and too limited to be of an substantial value, I was looking to see, as my first set of tests, in fact, the very first code I ever wrote using vector and I was blown away. I started off with a thousand random numbers being stuffed into both vector and CArray, there was no difference, so went up to 10,000; small difference. So I said "Hell, a million iterations should have very visible results." A guy passing by my office gave me an odd look and I starting adding these mini tests. I will explain my results below.

Added without reserve to Vector<int> in 1.36 seconds
Removed all Vector<int> elements in 0.14 seconds
I added 1 million random numbers to a freshly declared vector<int>, it took 1.36 seconds and
.14 seconds to dump them all again
Added with reserve and push_back to Vector<int> in0.922 seconds
Removed all Vector<int> elements in 0.141 seconds
This time, I used vector.reserve() to reserve the memory first and the time was reduced.
(I used push_back to add the elements)
Added with reserve and [] to Vector<int> in 0.203 seconds
Removed all Vector<int> elements in 0 seconds
This time I reserved the memory and did direct access [] to each element to insert the integers
It was even quicker.
Added without SetSize to CArray<int, int> in 252.828 seconds
Removed all CArray elements in 0.031 seconds
Now I repeat the above but with CArray; the freshly declared array obviously bungles its way
around reallocating memory.
Added with SetSize and Add to CArray<int, int> in 768.796 seconds
Removed all CArray elements in 0.047 seconds
This test was screwed up because I forgot that SetSize() really sets the size of the array
and if you use CArray.Add(), you add still increase the size of the array, so it was insanely
longer.
Added with SetSize and SetAt to CArray<int, int> in 0.156 seconds
Removed all CArray elements in 0.031 seconds
But, using set SetSize and adding the elements with SetAt was the absolute fastest of them all.

My interpretation of the results are that if you are going to add elementes to a dynamically allocating array with an as yet undertermined size, use STL::vector. But, if you know what size the array must be and it will NEVER get bigger, CArray wins my vote. But, if the section of code is not GUI related, I don't think I am going to be using MFC anyway, I don't think less than 8/10ths of a second is going to be that crucial - I hope Smile | :)

And just so you know, I am not here to prove or disprove anything to anyone but myself. I taught myself C++ in a hurry so I could fill an emergency roll as software developer 6 years ago. And I've been there ever since, even after a hostile takeover. Now I want to start learning the best way to do things. For me, comparing tests like this against what I already know is a great method of learning the tech and reinfocing its value.

Thank you for all your inpout and I hope you'll humor me further down the road.
John
GeneralRe: STL vs. MFC Pin
Christian Graus10-Jan-03 9:33
protectorChristian Graus10-Jan-03 9:33 
GeneralRe: STL vs. MFC Pin
lpvoid10-Jan-03 13:05
lpvoid10-Jan-03 13:05 
GeneralRe: STL vs. MFC Pin
Tim Smith6-Jan-03 9:57
Tim Smith6-Jan-03 9:57 
GeneralRe: STL vs. MFC Pin
lpvoid7-Jan-03 2:52
lpvoid7-Jan-03 2:52 
GeneralRe: STL vs. MFC Pin
valikac6-Jan-03 16:10
valikac6-Jan-03 16:10 
GeneralRe: STL vs. MFC Pin
lpvoid7-Jan-03 3:00
lpvoid7-Jan-03 3:00 
GeneralRe: STL vs. MFC Pin
valikac7-Jan-03 4:43
valikac7-Jan-03 4:43 
GeneralRe: STL vs. MFC Pin
lpvoid7-Jan-03 5:48
lpvoid7-Jan-03 5:48 
GeneralRe: STL vs. MFC Pin
valikac7-Jan-03 9:02
valikac7-Jan-03 9:02 
GeneralRe: STL vs. MFC Pin
User 98858-Jan-03 10:06
User 98858-Jan-03 10:06 
GeneralRe: STL vs. MFC Pin
User 98859-Jan-03 2:36
User 98859-Jan-03 2:36 
GeneralRe: STL vs. MFC Pin
Tim Smith9-Jan-03 4:04
Tim Smith9-Jan-03 4:04 
GeneralRe: STL vs. MFC Pin
User 98859-Jan-03 5:12
User 98859-Jan-03 5:12 
GeneralRe: STL vs. MFC Pin
Tim Smith9-Jan-03 15:08
Tim Smith9-Jan-03 15:08 
GeneralRe: STL vs. MFC Pin
lpvoid10-Jan-03 13:45
lpvoid10-Jan-03 13:45 
GeneralRe: STL vs. MFC Pin
lpvoid10-Jan-03 16:48
lpvoid10-Jan-03 16:48 
GeneralHelp with ATL 7.0 Pin
Binky6-Jan-03 8:12
Binky6-Jan-03 8:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.