Click here to Skip to main content
15,919,613 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help me... Pin
david_gilmour2-Dec-04 21:07
david_gilmour2-Dec-04 21:07 
GeneralRe: Help me... Pin
David Crow3-Dec-04 2:20
David Crow3-Dec-04 2:20 
Generalmessagebox problem Pin
tiziacaia2-Dec-04 18:41
tiziacaia2-Dec-04 18:41 
GeneralRe: messagebox problem Pin
Nish Nishant2-Dec-04 19:27
sitebuilderNish Nishant2-Dec-04 19:27 
GeneralRe: messagebox problem Pin
tiziacaia3-Dec-04 5:45
tiziacaia3-Dec-04 5:45 
GeneralRe: messagebox problem Pin
V.2-Dec-04 23:15
professionalV.2-Dec-04 23:15 
AnswerRe: How much overhead does std::vector have? Pin
John R. Shaw2-Dec-04 18:30
John R. Shaw2-Dec-04 18:30 
AnswerRe: How much overhead does std::vector have? Pin
Tim Smith3-Dec-04 4:31
Tim Smith3-Dec-04 4:31 
It really depends on how you are using std::vector. If you don't use reserve and then just push_back each entry, then the vector will grow using a simple doubling algorithm.

For example, push_pack one item and the new size is 1 elements used, 1 element allocated (1U/1A). If you push back another, vector needs to resize the memory so it doubles the size resulting in 2U/2A. On the next push_back it doubles again resulting in 3U/4A. Next push back doesn't require a reallocate, 4U/4A. The next one doubles again, 5U/8A.

Now, given you need to store 100,000,000, the doubling algorithm would result in 134,217,728 elements allocated. This is a waste of a lot of memory.

But that is only half the problem. Everytime that memory is reallocated, it runs the risk of fragmenting your memory. When you are talking about a few KB here and there, it isn't a problem. When you start talking about MB blocks of memory, you will end up with a lot of "free" memory that was once allocated but isn't being used since the bigger allocation can't fit into that block. So you could easily be wasting another 400MB of memory.

BUT, this isn't a problem with vector, it would be a problem with how you are using it. Use reserve to pre-allocate the vector size. Once that is done, what the other guy said would be true.

Tim Smith

I'm going to patent thought. I have yet to see any prior art.
GeneralRe: How much overhead does std::vector have? Pin
Robert Buldoc3-Dec-04 6:55
Robert Buldoc3-Dec-04 6:55 
QuestionMaking my own OpenGL, what to do about wgl* entrypoints? Pin
maxmaven2-Dec-04 18:23
maxmaven2-Dec-04 18:23 
GeneralPlease help immediately!! Pin
angello62-Dec-04 18:03
angello62-Dec-04 18:03 
GeneralRe: Please help immediately!! Pin
John R. Shaw2-Dec-04 18:50
John R. Shaw2-Dec-04 18:50 
GeneralRe: Please help immediately!! Pin
david_gilmour2-Dec-04 21:29
david_gilmour2-Dec-04 21:29 
GeneralRe: Please help immediately!! Pin
Jon Hulatt3-Dec-04 2:22
Jon Hulatt3-Dec-04 2:22 
GeneralRe: Please help immediately!! Pin
John R. Shaw4-Dec-04 9:17
John R. Shaw4-Dec-04 9:17 
GeneralRe: Please help immediately!! Pin
Jon Hulatt3-Dec-04 2:24
Jon Hulatt3-Dec-04 2:24 
QuestionHow to compare two files quickly? Pin
Jelfy2-Dec-04 17:53
Jelfy2-Dec-04 17:53 
AnswerRe: How to compare two files quickly? Pin
Member 3076122-Dec-04 19:27
Member 3076122-Dec-04 19:27 
AnswerRe: How to compare two files quickly? Pin
Henry miller3-Dec-04 3:33
Henry miller3-Dec-04 3:33 
GeneralRe: How to compare two files quickly? Pin
Harold Bamford3-Dec-04 5:40
Harold Bamford3-Dec-04 5:40 
AnswerRe: How to compare two files quickly? Pin
Antony M Kancidrowski3-Dec-04 5:39
Antony M Kancidrowski3-Dec-04 5:39 
QuestionHow to add Check Boxes to every Column data using C++ to a List Control? Pin
pubududilena2-Dec-04 17:50
pubududilena2-Dec-04 17:50 
AnswerRe: How to add Check Boxes to every Column data using C++ to a List Control? Pin
David Crow3-Dec-04 2:25
David Crow3-Dec-04 2:25 
QuestionWindows MIDI driver(usb).....can anyone tell me functions that handle this? Pin
namaskaaram2-Dec-04 17:35
namaskaaram2-Dec-04 17:35 
QuestionHow much overhead does std::vector have? Pin
Robert Buldoc2-Dec-04 16:53
Robert Buldoc2-Dec-04 16: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.