How do can i properly increase the stack available for a program using either Bloodshed Dev C++ or Code::Block? Im running simple bubble and quick sort that work, but when i changed the stack in Code::Block (found out how over here) it made my program crash even faster, despite using much more than suggested space. originally, the program was crashing while sorting 64K of random integers (using the rand()
function). Now, its crashing at 32K. im getting the error: Process returned -1073741571 (0xC00000FD)
the program actually runs faster without having the stack changed, assuming im doing it right. gcc -Wl,--stack,1099511627776
i cant figure out how to change it at all in Dev C++
What should i do? is there any way to change the stack within the code itself? here is the code im using for bubble and quick sort. there are two of each: one is with vectors, the other is with arrays. i think that the bubble sort. should be correct. the quick sort, im not so sure about. sorry if its a bit messy
vector <int> v_bubble(vector <int> array){
// Vector Bubble Sort
if (array.size() < 2){
return array;
}
int s = 1;
while (s){
s = 0;
for (unsigned int x = 0; x < (array.size() - 1); x++){
if (array[x] > array[x + 1]){
int t = array[x];
array[x] = array[x + 1];
array[x + 1] = t;
s = 1;
}
}
}
return array;
}
void a_bubble(int array[], int size){
// Array Bubble Sort
int s = 1;
while (s){
s = 0;
for (int x = 0; x < (size - 1); x++){
if (array[x] > array[x + 1]){
int t = array[x];
array[x] = array[x + 1];
array[x + 1] = t;
s = 1;
}
}
}
}
vector <int> v_quick(vector <int> array){
//Vector Quick Sort
if (array.size() < 2){
return array;
}
vector <int> left;
vector <int> right;
int p_location = array.size() / 2 - 1;
int pivot = array[p_location];
for(unsigned int x = p_location; x < array.size() - 1; x++){
array[x] = array[x + 1];
}
array.pop_back();
for(unsigned int x = 0; x < array.size(); x++){
if (array[x] <= pivot) {
left.push_back(array[x]);
}
else if (array[x] > pivot){
right.push_back(array[x]);
}
}
vector <int> p;
p.push_back(pivot);
return combine(combine(v_quick(left), p), v_quick(right));
}
int a_quick(int array[], int size, int l_index = -1, int r_index = -1){
//Array Quick Sort
if (size < 2){
return array[size];
}
array[size] = array[size];
int left[size];
int right[size];
l_index = 0;
r_index = 0;
int p_location = size / 2 - 1;
int pivot = array[p_location];
for(int x = p_location; x < size - 1; x++){
array[x] = array[x + 1];
}
size--;
for(unsigned int x = 0; x < size; x++){
if (array[x] <= pivot) {
left[l_index] = array[x];
l_index++;
}
else if (array[x] > pivot){
right[r_index] = array[x];
r_index++;
}
}
return a_quick(left, l_index, l_index, r_index) + pivot + a_quick(right, r_index, l_index, r_index);
}
the rest of the code is simply generating arrays and vectors with 32, 64 and 128 k entries, sorting them using the above code and returning the time. that part im pretty sure i did not screw up
my main is basically just
start = clock();
a_quick(array1, 32000);
end = clock();
cout << "\nQuick Sort\tArray\t32000\t" << ((double) end - start)/CLOCKS_PER_SEC << " seconds\n";
over and over again