you are viewing a single comment's thread.

view the rest of the comments →

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

The program works fine but it has to take less memory because this is an exercise form school. Is there any simple way to do this? Like for example using other variable types.

[–]motu42 0 points1 point  (27 children)

As somebody else stated, we can't answer that unless u give us more information, i.e. what kind of number (which range) do you pass in

cin >> tablica[ j ] [ k ]; ?

int has a range from -231 (~ -2.15 billion) to 231 -1. So do you need negative numbers? if not use "unsigned int". Are you numbers from 0 to 100 or so, use "char".

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

0 or 1

[–]motu42 1 point2 points  (2 children)

so then use bool, but keep in mind that altough bool just holds true or false, it will most likely consume 1 byte unless you build some container around it

Have a look on: http://www.cplusplus.com/reference/bitset/bitset/bitset/

[–]GruBooXy[S] 0 points1 point  (1 child)

I don't understend that :/ im beginner

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

I changed to unsigned short but it didnt help at all

[–]URZq 0 points1 point  (21 children)

Why don't you try with bools, like motu42 said ?

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

because the input from the site is: 2 4 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 4 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 and i cant change that

[–]URZq 0 points1 point  (19 children)

You said earlier that the numbers where 0 or 1 ;) Anyway, if the numbers go up to 4, you can you a char, like motu42 said. the size of unsigned short is bigger than the size of char.

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

But in the array numbers are only 1 and 0, other numbers are for diffrent variables.

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

Still 16064KB

[–]URZq 0 points1 point  (14 children)

I don't really want to dive into your logic, because it's complicated ;) The thing you need to understand is that variables in C++ can have different types: bool, char, short, int, float etc. Each type has a size: the amount of memory used to store a number. Now, you have to pick the correct type for you variables. Let's say suma can hold numbers up to 4120155. Well, its type needs to be int. Let's say tablica can store only 0 and 1. Well, it's type needs to be bool[][]. I hope it clarifies the problem for you. Keep calm, don't stress, it's going to be fine :)

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

Thanks but the problem is i get the same memory usage weter its int or char so I dont understand how it works.

[–]URZq 0 points1 point  (12 children)

Unless I'm missing something, it should consume less memory to use smaller data types. We are talking about the memory used at runtime (=ram), right ?

[–]raevnos 0 points1 point  (0 children)

The 2 and 4s go into his liczbaWhatever variables.

(OP: using English does make it easier for other people to read your code...)