vector memeory allocation

Hello
I am trying to allocate a memory to vector but while running the program,my window appear and PC get halt state then i have to force fully shutdown my PC
I found that due to the vector i am getting this problem.
Can any one tell whether i am writing a wrong code
1
2
3
4
5
6
7
8
9
10
11
#define SCOPEPLOT_MAXNUM_SAMPLES (1000000)
QHash<int, std::vector<double>*> m_sampleHash;

  m_sampleHash.insert(1, new std::vector<double>(SCOPEPLOT_MAXNUM_SAMPLES));
   std::vector<double>* vec_p = m_sampleHash.value(1);
	for(int k = 0;k < numSamples;k++)
	{
		count++;
		vec_p->at(k) = data_p[k];
		
	}
closed account (N36fSL3A)
You're adding an extra parenthesis.m_sampleHash.insert(1, new std::vector<double>(SCOPEPLOT_MAXNUM_SAMPLES));

Fix:
m_sampleHash.insert(1, new std::vector<double>(SCOPEPLOT_MAXNUM_SAMPLES);
Extra Parenthesis Means

m_sampleHash.insert(1, new std::vector<double>(SCOPEPLOT_MAXNUM_SAMPLES);

This will give me a Compile time Error.
I don't know how you suggested this Answer...
Why are you using SCOPEPLOT_MAXNUM_SAMPLES at all?

1
2
3
4
5
6
7
8
9
10
11
12
#define SCOPEPLOT_MAXNUM_SAMPLES (1000000)
QHash<int, std::vector<double>*> m_sampleHash;

  m_sampleHash.insert(1, new std::vector<double>());
  // ...
  std::vector<double>* vec_p = m_sampleHash.value(1);
  vec_p->resize(numSamples);
  for(int k = 0; k < numSamples; k++)
  {
    count++;
    (*vec_p)[k] = data_p[k];
  }
Last edited on
apart from what kbw wrote i don't see anything within your code snippet that could cause a crash
closed account (N36fSL3A)
Oh >_> I didn't see that. Sorry.

It seems as this is the suspect:
for(int k = 0;k < numSamples;k++)

What's your full code? Are you initializing numSamples?
Topic archived. No new replies allowed.