Solved

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

Posted on 2006-06-09
6
249 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
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

773 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