Solved

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

Posted on 2006-06-09
6
241 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Hanqian
Comment Utility
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
Comment Utility
*Please do not accept this for points*

Those numbers for capacity look good.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Nope, looks good to me also.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now