Click here to Skip to main content
15,907,905 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
QuestionHow I can get listview subitem text of a listview on another process? Pin
Marco225028-Aug-06 9:05
Marco225028-Aug-06 9:05 
QuestionGet Parent handle in ATL Windowless Control Pin
QuickDeveloper27-Aug-06 22:50
QuickDeveloper27-Aug-06 22:50 
AnswerRe: Get Parent handle in ATL Windowless Control Pin
Roland Rüdenauer17-Sep-06 12:02
Roland Rüdenauer17-Sep-06 12:02 
Questionowner draw CReBarCtrl [modified] Pin
Max Santos26-Aug-06 6:22
Max Santos26-Aug-06 6:22 
AnswerRe: owner draw CReBarCtrl Pin
Justin Tay26-Aug-06 15:58
Justin Tay26-Aug-06 15:58 
AnswerRe: owner draw CReBarCtrl Pin
count08-Sep-06 17:50
count08-Sep-06 17:50 
Questionvector vs. CByteArray [modified] Pin
bob1697225-Aug-06 4:06
bob1697225-Aug-06 4:06 
AnswerRe: vector vs. CByteArray Pin
Stuart Dootson25-Aug-06 5:33
professionalStuart Dootson25-Aug-06 5:33 
bob16972 wrote:
How do I set the initial size and grow by values for vector


Initial size can be set using the resize method, although the reserve method is also useful - it allows you to say 'I want the vector to allocate storage for at least n elements - but I don't need to use it just yet'. You need to understand the difference between size (the number of elements a container contains) and capacity (the number of elements it has storage for) - that's quite an important thing.

So, for example, the following allocates space for at least three elements, and you can push_back three times after that knowing that no more allocations will be performed:

std::vector<int> vec;
vec.reserve(3);
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);


You might also want to investigate std::deque - this allocates storage as a linked list of blocks, meaning that new allocations don't require relocation of existing elements.

As for GrowBy - you're out of luck there - I believe that most STL implementations tend to double the size of a vector on reallocation - but I 'm quite likely to be wrong! (And, in fact, on checking with VC7.1, I am! It allocates an extra 50% on each reallocation:

#include <iostream>
#include <vector>

int main(int, char**)
{
   std::vector<int> a;

   size_t cap = a.capacity();
   for(int i =0;i<100000000;++i)
   {
      a.push_back(i);
      if (cap != a.capacity())
      {
         cap = a.capacity();
         std::cout << "Reallocation! -> " << cap << " elements\n";
      }
   }
}


gives

Reallocation! -> 1 elements
Reallocation! -> 2 elements
Reallocation! -> 3 elements
Reallocation! -> 4 elements
Reallocation! -> 6 elements
Reallocation! -> 9 elements
Reallocation! -> 13 elements
Reallocation! -> 19 elements
Reallocation! -> 28 elements
Reallocation! -> 42 elements
Reallocation! -> 63 elements
Reallocation! -> 94 elements
Reallocation! -> 141 elements
Reallocation! -> 211 elements
Reallocation! -> 316 elements
Reallocation! -> 474 elements
Reallocation! -> 711 elements
Reallocation! -> 1066 elements
Reallocation! -> 1599 elements
Reallocation! -> 2398 elements
Reallocation! -> 3597 elements
Reallocation! -> 5395 elements
Reallocation! -> 8092 elements
Reallocation! -> 12138 elements
Reallocation! -> 18207 elements
Reallocation! -> 27310 elements
Reallocation! -> 40965 elements
Reallocation! -> 61447 elements
Reallocation! -> 92170 elements
Reallocation! -> 138255 elements
Reallocation! -> 207382 elements
Reallocation! -> 311073 elements
Reallocation! -> 466609 elements
Reallocation! -> 699913 elements
Reallocation! -> 1049869 elements
Reallocation! -> 1574803 elements
Reallocation! -> 2362204 elements
Reallocation! -> 3543306 elements
Reallocation! -> 5314959 elements
Reallocation! -> 7972438 elements
Reallocation! -> 11958657 elements
Reallocation! -> 17937985 elements
Reallocation! -> 26906977 elements
Reallocation! -> 40360465 elements
Reallocation! -> 60540697 elements
Reallocation! -> 90811045 elements
Reallocation! -> 136216567 elements


In your case, I'd allocate your approximate initial size. If it is a reasonably good approximation, then an extra 50% should be sufficient for any overflow?

GeneralRe: vector vs. CByteArray Pin
bob1697225-Aug-06 5:55
bob1697225-Aug-06 5:55 
GeneralRe: vector vs. CByteArray Pin
Zac Howland25-Aug-06 7:48
Zac Howland25-Aug-06 7:48 
GeneralRe: vector vs. CByteArray Pin
Stuart Dootson28-Aug-06 21:13
professionalStuart Dootson28-Aug-06 21:13 
GeneralRe: vector vs. CByteArray Pin
Zac Howland29-Aug-06 4:26
Zac Howland29-Aug-06 4:26 
GeneralRe: vector vs. CByteArray Pin
Jörgen Sigvardsson30-Aug-06 21:25
Jörgen Sigvardsson30-Aug-06 21:25 
QuestionHow to use WTL's CDoubleBufferImpl Pin
shaohao25-Aug-06 4:04
shaohao25-Aug-06 4:04 
AnswerRe: How to use WTL's CDoubleBufferImpl Pin
Stuart Dootson25-Aug-06 5:34
professionalStuart Dootson25-Aug-06 5:34 
AnswerRe: How to use WTL's CDoubleBufferImpl Pin
Michael Dunn25-Aug-06 7:39
sitebuilderMichael Dunn25-Aug-06 7:39 
QuestionCalling a ATL COM DLL interface from VBScript routine Pin
AKSIVAKUMAR23-Aug-06 23:11
AKSIVAKUMAR23-Aug-06 23:11 
QuestionHow does the WTL CString compare with CString from MFC? Pin
TClarke23-Aug-06 6:43
TClarke23-Aug-06 6:43 
AnswerRe: How does the WTL CString compare with CString from MFC? Pin
Stuart Dootson23-Aug-06 8:48
professionalStuart Dootson23-Aug-06 8:48 
AnswerRe: How does the WTL CString compare with CString from MFC? Pin
Zac Howland23-Aug-06 9:54
Zac Howland23-Aug-06 9:54 
AnswerRe: How does the WTL CString compare with CString from MFC? Pin
Michael Dunn23-Aug-06 11:56
sitebuilderMichael Dunn23-Aug-06 11:56 
GeneralRe: How does the WTL CString compare with CString from MFC? Pin
TClarke23-Aug-06 23:06
TClarke23-Aug-06 23:06 
QuestionUsing WTL with ATL to enhance ActiveX controls Pin
TClarke23-Aug-06 6:39
TClarke23-Aug-06 6:39 
AnswerRe: Using WTL with ATL to enhance ActiveX controls Pin
Jörgen Sigvardsson26-Aug-06 9:24
Jörgen Sigvardsson26-Aug-06 9:24 
GeneralRe: Using WTL with ATL to enhance ActiveX controls Pin
TClarke28-Aug-06 22:26
TClarke28-Aug-06 22:26 

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.