how to solve this problem?

K

kathy

I have a piece of code:

....
std::vector< double > vProcessedSpectrum;
vProcessedSpectrum.resize( 1 );
vProcessedSpectrum.resize( 10 );
vProcessedSpectrum.resize( 102 );
vProcessedSpectrum.resize( 1024 ); //error happened here!
....

When I resize the vector to some big number, I got error:
"Debug Error" and break into the "ctr0msg.c".

How to fix the problem?
 
R

Rolf Magnus

kathy said:
I have a piece of code:

...
std::vector< double > vProcessedSpectrum;
vProcessedSpectrum.resize( 1 );
vProcessedSpectrum.resize( 10 );
vProcessedSpectrum.resize( 102 );
vProcessedSpectrum.resize( 1024 ); //error happened here!
...

When I resize the vector to some big number, I got error:
"Debug Error" and break into the "ctr0msg.c".

How to fix the problem?

Please provide a minimal, but complete program that demonstrates the
problem.
 
K

kathy

Rolf said:
Please provide a minimal, but complete program that demonstrates the
problem.

There are a lot of fuction / object call. Just put the object there
might not helpful
 
M

mlimber

kathy said:
There are a lot of fuction / object call. Just put the object there
might not helpful

He means that you should try to reduce your program to something short
but *complete* that demonstrates the problem you are describing.

Cheers! --M
 
K

kathy

mlimber said:
He means that you should try to reduce your program to something short
but *complete* that demonstrates the problem you are describing.

Cheers! --M

I know. But if I get rid of other code with only the posted code there.
It works fine.
I do not know where the problem come from.
 
R

Rolf Magnus

kathy said:
I know. But if I get rid of other code with only the posted code there.
It works fine.

Then it's likely that the error came from the code you got rid of and not
the code you posted, in which case nobody can help you.
You should try to reduce your code in small steps. As soon as it starts
working, the part that you removed last is likely to contain the error.
I do not know where the problem come from.

Neither does anyone else here.
 
K

kathy

Then it's likely that the error came from the code you got rid of and not
the code you posted, in which case nobody can help you.
You should try to reduce your code in small steps. As soon as it starts
working, the part that you removed last is likely to contain the error.

question is:

If I moved out the error line, every thing works fine. If I add it, it
cause the error:

....
Processed_Spectrum.resize(452);//error here, but
Processed_Spectrum.resize(451) ok
....

It looks like somewhere memory leaking. But I try to stop some
processes and rerun mine. I still get error - always error at
resize(452). I expected error happened at somewhere > 452.
 
P

phlip

kathy said:
...
Processed_Spectrum.resize(452);//error here, but
Processed_Spectrum.resize(451) ok
...

It looks like somewhere memory leaking. But I try to stop some
processes and rerun mine. I still get error - always error at
resize(452). I expected error happened at somewhere > 452.

Your program corrupted memory before these lines. The corruption remained
hidden until these lines discovered it.

You need to remove _all_ your program, in big chunks, to see which chunk
contains that corruption. Or you can inspect the high-risk areas manually,
or use a tool like Purify or Valgrind.
 
H

Howard

kathy said:
question is:

If I moved out the error line, every thing works fine. If I add it, it
cause the error:

...
Processed_Spectrum.resize(452);//error here, but
Processed_Spectrum.resize(451) ok
...

It looks like somewhere memory leaking. But I try to stop some
processes and rerun mine. I still get error - always error at
resize(452). I expected error happened at somewhere > 452.

Are you saying that you get an error any time you pass a number that is 452
or higher to resize()? Or, do you mean that you're actually calling resize
multiple times, but it's crashing after several calls to resize()?

The code you have shown does not appear to have a problem. That is why it
has been suggested that you look at other code, which gets executed _before_
the one that you've shown. Something earlier may be trashing memory, and it
only shows up when you try to resize with a larger value.

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,048
Members
48,769
Latest member
Clifft

Latest Threads

Top