Click here to Skip to main content
15,915,611 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
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 
My point was:

If i declare a CArray and SetSize(), GetCount() and GetSize() returns the same value - the value set by SetSize(). Internally, the memory allocation for a SetAt is done just to cover the number of items required.

However, a vector allows me to reserve a size. Even if I don't reserve the insert causes a larger memory allocation, thereby not requiring resize, if I do not reserve.

Hence, if I want upto 150 items in a container and want to know how many items are there at a particular time, I use reserve(150) to reserve the maximum space and size() to get the actual number of params. The value returned by size is updated only if you use insert or push_back, and not the [] operator.

In a CArray, if i want to know the number of items that I added, i cannot find it if I used SetSize(). Instead, I have to rely on the default memory management of CArray which is to create memory for only the number of items that it needs.

vector can be used the same way by using reserve, and creating a pointer p that points to the start of the vector (T* p = &v[0]) and using p[i] to access the elements. But, there may be a number of free locations in between (CArray behaves the same way), there by eliminating the possibility of using any of the other STL algorithms.

SetSize() is similar to resize() and there is nothing corresponding to reserve(). The default memory allocation done when inserting a new item is better in vector, because it allocates more space so that subsequent inserts are faster.





My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers


modified 29-Aug-18 21:01pm.

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 
Generalmap of _variant_t Pin
[James Pullicino]5-Jan-03 21:57
[James Pullicino]5-Jan-03 21:57 
GeneralRe: map of _variant_t Pin
Michael Dunn5-Jan-03 22:14
sitebuilderMichael Dunn5-Jan-03 22:14 
GeneralRe: map of _variant_t Pin
[James Pullicino]5-Jan-03 22:20
[James Pullicino]5-Jan-03 22:20 
GeneralRe: map of _variant_t Pin
Jörgen Sigvardsson17-Jan-03 12:26
Jörgen Sigvardsson17-Jan-03 12:26 
GeneralProblem with WTL Pin
Ph@ntom5-Jan-03 18:43
Ph@ntom5-Jan-03 18:43 
GeneralRe: Problem with WTL Pin
Michael Dunn5-Jan-03 20:40
sitebuilderMichael Dunn5-Jan-03 20:40 
GeneralRe: Problem with WTL Pin
User 98858-Jan-03 10:14
User 98858-Jan-03 10:14 
GeneralWTL: a newbie question Pin
Shah Shehpori5-Jan-03 18:41
sussShah Shehpori5-Jan-03 18:41 
GeneralRe: WTL: a newbie question Pin
Jörgen Sigvardsson17-Jan-03 12:29
Jörgen Sigvardsson17-Jan-03 12:29 
GeneralCRegKey QueryStringValue Pin
rbeckett5-Jan-03 17:01
rbeckett5-Jan-03 17:01 
GeneralRe: CRegKey QueryStringValue Pin
Michael Dunn5-Jan-03 17:24
sitebuilderMichael Dunn5-Jan-03 17:24 
GeneralGreat! Works Perfectly! Pin
rbeckett5-Jan-03 17:41
rbeckett5-Jan-03 17:41 
QuestionHow do I create Different view derived class ? Pin
Jose Cruz3-Jan-03 6:45
Jose Cruz3-Jan-03 6:45 

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.