?
Solved

Help to resolve this error message caused in using Vector.push_back.

Posted on 2006-06-09
6
Medium Priority
?
256 Views
Last Modified: 2010-04-01
Dear expert,

I have the code:
std::vector<int> rank;

rank.push_back(0) is called is a loop, rank.push_back(0) works fine first 9 calls but has following error when it is called at 10th call.

Error message from BoundsChecker:
Dynamic memory overrun
32 byte block allocated in c:\program files\microsoft visual studio\vc98\include\xmemory (30)
HANDLE: 0x02DE16A0
allocating thread ID: 0x9CC, current thread ID: 0x9CC

Please help! Thanks.

Hanqian
0
Comment
Question by:Hanqian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 16871022
try

rank.reserve(16);

If you then get the message at the 16th or 17th call, you can be sure that it is safe to ignore it, since it would mean that BoundsChecker takes vector resizing as an error (which it isn't).
0
 

Author Comment

by:Hanqian
ID: 16871168
I put rank.reserve(16) at begining of my loop, I don't see error message any more. Does it mean my error is fixed?

Xia
0
 
LVL 86

Expert Comment

by:jkr
ID: 16871360
I doubt that there ever was a real error, but if the message is gone, I'd say yes. You can verify the default capacity for vectors in your STL implementation using e.g.

cout << rank.capacity() << endl;

*before* calling 'reserve()' - I assume the output will be '10'.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Hanqian
ID: 16871515
Print cout << rank.capacity() << endl;
 for each call without adding rank.resever() , these are numbers returned:
1th call: 0
2th call: 1
3th call: 2
     :       4
     :       4
     :      8
            8
            8
            8
           16

Anything wrong?

Hanqian
0
 
LVL 8

Expert Comment

by:List244
ID: 16871701
*Please do not accept this for points*

Those numbers for capacity look good.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16871745
Nope, looks good to me also.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question