-1
long int const qwerty= 500000;
double ex[qwerty];

My signal have 500k of sample. i need to have it in complex or double but always got a error 'System.StackOverflowException' occurred in Project1.exe" Why is that ?. When qwerty is lower than 20k everything works fine.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
dragi
  • 21
  • 5
  • Use a std::vector (or maybe std::array). You **could** use `double* ex=new double[qwerty]` but you shouldn't. The overhead of `std::vector` is so small that you have no excuse for doing things the hard way. (Someone might suggest the correct `unique_ptr` syntax as more efficient than `vector` for this use and equally safe. But I don't think that is worth the extra thought required). – JSF Jan 07 '16 at 16:28
  • When you want a tiny C array, especially if you often access it with indexes known at compile time ( such as `ex[0]=ex[2]-ex[1];` etc.), there may be significant performance benefits to declaring it as a function local (automatic) C array. But when it is bigger (and has access patterns typical of bigger arrays) the relative performance benefits of C arrays tend to vanish and the stack size problems arise. So use a `vector` instead. – JSF Jan 07 '16 at 16:37
  • What does this have to do with [`std::complex`](http://en.cppreference.com/w/cpp/numeric/complex)? Also, you are unambiguously in C++/CLI, not C++. – Deduplicator Jan 07 '16 at 17:21

1 Answers1

0

You are creating an array of 500k on the stack. The stack has limited memory. If you want to create something that big allocate it on the heap.

Edit: Or better yet, use std::vector. source

Tarik Neaj
  • 548
  • 2
  • 10