Solved

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

Posted on 2006-06-09
6
252 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 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