Link to home
Start Free TrialLog in
Avatar of Hanqian
Hanqian

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hanqian
Hanqian

ASKER

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
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'.
Avatar of Hanqian

ASKER

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
*Please do not accept this for points*

Those numbers for capacity look good.
Nope, looks good to me also.