Hi, this is a program meant to do a counting sort, but for some reason, when I run the program, i did not see any result that I cout. I already have a file linked to my ifstream. Thank you.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
int total[INT_MAX], number[101]={0}, x=0, i, j, y, m=0;
ifstream in("data.txt");
while (in>>total[x])x++;
Assuming INT_MAX to be 2147483647, an array of 2147483647 int values would take up 2147483647 * 4 = 8589934588 bytes, which is about 8.5 GB
The stack typically has a few MB of memory available, so there's no way this could go on the stack. Even putting that on the heap would tax some systems.
Some systems have ints of size 8 bytes rather than 4 bytes; if INT_MAX is the same and an int consumes 8 bytes rather than 4, this array would need 17 GB of memory.
How much memory does your system have? Do you really need an array that takes up 8.5GB?
Hi,
I tested out the program and it works fine. Thank you very much for your help. I realized that my system only have a RAM of 8 GB, causing my previous program to crash. Thank you very much for both of your help.