Click here to Skip to main content
15,898,538 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Geting a Controls ID from a HWND. Pin
valikac25-Sep-02 10:58
valikac25-Sep-02 10:58 
GeneralSTL advice required Pin
User 988525-Sep-02 4:23
User 988525-Sep-02 4:23 
GeneralRe: STL advice required Pin
TyMatthews25-Sep-02 4:34
TyMatthews25-Sep-02 4:34 
GeneralRe: STL advice required Pin
User 988525-Sep-02 4:41
User 988525-Sep-02 4:41 
GeneralRe: STL advice required Pin
Lanny Thompson25-Sep-02 4:53
Lanny Thompson25-Sep-02 4:53 
GeneralRe: STL advice required Pin
User 988525-Sep-02 5:04
User 988525-Sep-02 5:04 
GeneralRe: STL advice required Pin
Lanny Thompson25-Sep-02 5:25
Lanny Thompson25-Sep-02 5:25 
GeneralRe: STL advice required Pin
TyMatthews25-Sep-02 6:43
TyMatthews25-Sep-02 6:43 
I would have to agree. The only problem with vector is that it is implemented as a contiguous block of memory, like an array. If you keep growing the vector, it becomes expensive to keep adding elements since it has to constantly keep allocating and moving things around to keep it contiguous. A list would solve that, but of course you lose the random access iterator. In addition, repeated sorts on a vector consume more CPU cycles than say a list since a vector has to shuffle data around whereas a list would just shuffle pointers.

Use reserve() right away with your vector to pre-allocate a specific number of elements. This will save time overall since it can immediately allocate its chunk in one fell swoop as opposed to constantly having to re-allocate and move the existing chunk every time you do a push_back as the vector begins to grow. If you have a rough idea of how many elements will be required, you can play with this reserved amount to get the right mix of as few resizes as possible during the life of the vector.

For example, if you grow your vector from 1 to 1024 elements, it would take 11 resizes if no initial reserve is set. If you set the reserve to 512, there would only be two resizes. The disadvantage is the "wasted" memory as the vector grows to reach 512 elements. Memory versus CPU time is the age-old quandary Smile | :)

Ty


"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein


GeneralRe: STL advice required Pin
Tomasz Sowinski25-Sep-02 5:34
Tomasz Sowinski25-Sep-02 5:34 
GeneralRe: STL advice required Pin
User 988525-Sep-02 5:52
User 988525-Sep-02 5:52 
GeneralRe: STL advice required Pin
Todd Smith25-Sep-02 7:02
Todd Smith25-Sep-02 7:02 
GeneralRe: STL advice required Pin
User 988525-Sep-02 8:06
User 988525-Sep-02 8:06 
GeneralRe: STL advice required Pin
Joaquín M López Muñoz26-Sep-02 9:00
Joaquín M López Muñoz26-Sep-02 9:00 
GeneralInclusion of C file Pin
RuiSantiago25-Sep-02 4:18
RuiSantiago25-Sep-02 4:18 
GeneralRe: Inclusion of C file Pin
Carlos Antollini25-Sep-02 4:23
Carlos Antollini25-Sep-02 4:23 
GeneralRe: Inclusion of C file Pin
Lanny Thompson25-Sep-02 4:29
Lanny Thompson25-Sep-02 4:29 
GeneralRe: Inclusion of C file Pin
SteveKing25-Sep-02 4:29
SteveKing25-Sep-02 4:29 
GeneralRe: Inclusion of C file Pin
RuiSantiago25-Sep-02 4:38
RuiSantiago25-Sep-02 4:38 
GeneralVC++ 6.0 problem : *.pch,*.obj ... I havent so much space for all... Pin
Wizard_0125-Sep-02 4:12
Wizard_0125-Sep-02 4:12 
GeneralRe: VC++ 6.0 problem : *.pch,*.obj ... I havent so much space for all... Pin
Carlos Antollini25-Sep-02 4:21
Carlos Antollini25-Sep-02 4:21 
GeneralRe: VC++ 6.0 problem : *.pch,*.obj ... I havent so much space for all... Pin
Wizard_0125-Sep-02 4:21
Wizard_0125-Sep-02 4:21 
GeneralRe: VC++ 6.0 problem : *.pch,*.obj ... I havent so much space for all... Pin
jmkhael25-Sep-02 4:56
jmkhael25-Sep-02 4:56 
GeneralRe: VC++ 6.0 problem : *.pch,*.obj ... I havent so much space for all... Pin
Brian Delahunty25-Sep-02 5:02
Brian Delahunty25-Sep-02 5:02 
GeneralRe: VC++ 6.0 problem : *.pch,*.obj ... I havent so much space for all... Pin
Carlos Antollini25-Sep-02 8:11
Carlos Antollini25-Sep-02 8:11 
QuestionMessage queue thread safety? Pin
jamiehale25-Sep-02 3:53
jamiehale25-Sep-02 3:53 

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.