DemonWasp @ Sun Jan 20, 2013 1:41 am wrote:
Each card can be represented by a value in the range 0-53 (8 bits). You can represent an entire hand in 5 bytes. Then if you allocate even 1MB of memory, you can store nearly 210,000 hands.
Even if you do store 75,000 hands at 10 ints = 40 bytes (assuming 32-bit integer, though that's not guaranteed with C/C++), that's still only 3MB of memory. Your computer probably has over 1000 times that.
Even your 'original' struct is only 25 bytes per card, which is less than 9MB of storage total.
I seriously don't think you're running out of memory.
There are a lot of other things that could cause your program to crash with the larger data set. Are you allocating any arrays of fixed size? Are you using any for loops over fixed ranges? Are you leaking heap-allocated strings? Are you multiple-delete or multiple-freeing? We can't help you answer that question without your full source code.
I think the default int is 4 bytes - i was using 6*4 (6 because I need to leave an empty spot in each hand for other reasons) = 24 bytes to store the values of the cards and 24 bytes to store the suits of the cards for each hand.
That is 48 bytes for each hand.
48 bytes * 75.000 = about 3.4 mb
Hmm you were right, that's nowhere close to running out of memory. (By the way, now I have a much better understanding of how big memory actually is, holy shit.)
I wonder why it didn't work before I changed from int to unsigned char, but it must have SOMETHING to do with less memory, otherwise what difference would changing from int to unsigned char make?