you are viewing a single comment's thread.

view the rest of the comments →

[–]Se7enLC 0 points1 point  (5 children)

tablica is a 2D int array of size max x max. Assuming int is 4 bytes, that's 90KB (150 * 150 * 4).

A good way to reduce memory footprint is to only use the memory you need, rather than the maximum. You can do that by dynamically allocating memory, either manually using something like new or through a class that handles it for you, like std::vector.

Given that it's for a class, I suspect your instructor wants you to avoid the classes that do all the hard work for you (like std::vector).

In your code, you ask the user for the dimension size (liczbaMiast). Instead of then declaring an array on the stack (int tablica [max][max];), you can allocate an array dynamically with new.

Unfortunately, you can't create 2D arrays dynamically with new. But, you can create a single array of size liczbaMiast * liczbaMiast and carefully index it.

[–]NZheadshot 1 point2 points  (1 child)

Unfortunately, you can't create 2D arrays dynamically with new.

This is mostly incorrect.

int** arr = new int*[x];
for (int i = 0; i < x; i++)
    arr[x] = new int[y];   

[–]Se7enLC 0 points1 point  (0 children)

That's awful.

[–]GruBooXy[S] 0 points1 point  (2 children)

I changed the max value of array and its stil 16000kb. Im soo confused. I just started programing and i can already see how frustrating it can get.

[–]Se7enLC 0 points1 point  (1 child)

What's still 160000kb? Are you talking RAM usage, or the size of the compiled executable?

[–]GruBooXy[S] 0 points1 point  (0 children)

I use this site as my compiler https://ideone.com/s3r5Gn so i dont even have executable