As far as I know, this isn\'t caused by an infinite recursion.
The program functioned correctly with smaller arrays (it is an audio editor). Now I have increased fun
You should not allocate large data structures on stack, because the stack's size is bounded. Allocate it on heap.
Even better, you should avoid manual allocation and use std::vector
, which will care for the memory allocation itself. As a bonus, you won't need to care about deallocation. (And this is the modern C++ way.)
By the way, if max_number_samples
is big, you should perhaps allocate only as much as you need:
std::vector<short int> reverse_data(track_samples);
(the rest of your code stays as it is).
Edit:
Even better idea: you can reverse your array in place, without copying into an additional array! Just go from index 0 to the half size and swap the i
th and (size - 1 - i)
th items:
for (i=0; i < track_samples/2; i++)
{
std::swap(sound_data[i], sound_data[track_samples-1-i]);
}
As Vlad pointed out, don't allocate 50MB on the stack.
But, the point is moot because you don't need to allocate any data. Try replacing your entire code fragment with a single call to std::reverse:
std::reverse(&sound_data[0], &sound_data[track_samples]);
#include <algorithm>
.