5
$\begingroup$

I've heard that YouTube had a problem with the view count on Gangnam style since the number of views exceeded the variable byte size.

What's the problem with creating really large variables? Why does it end with unsigned long, for example? Can you create bigger and bigger variables to hold more and more bytes? Is there any reason why programmers don't just use a really big variable for everything?

$\endgroup$
0

3 Answers 3

6
$\begingroup$

Yes, you can create bigger and bigger variables to store big integer. There are many libraries that provide that functionality. For example BigInteger in Java. The problem with using big integer is that it makes program slower as more instructions are required to perform operations such as addition. Moreover, using a bigger representation will consumes more memory.

$\endgroup$
6
$\begingroup$

What's the problem with creating really large variables?

The problem that it takes space. You need to put this "large large" variable somewhere in your memory. Say there are 81M videos stored on YouTube, multiply this by the amount of bytes you spend on this large-large variable, and you get a huge waste. Almost all the videos (i.e., all but one) can work fine with 4-8 bytes for their watch counter, so why keep 1KB (say) for every watch counter? That's throwing away 81GB of space for no good reason!

Creating a variable-size variable (as suggested in Tushar's answer) is also an option, but then the overhead becomes time. Instead of having a simple register that holds this data, whose handling takes $\ll 10$ clock cycles per operation, a variable-size one may take $>10$ and even $>100$ clocks to handle per operation. Why waste this time, when only a small fraction of the vidoes hit the 1B watches?

$\endgroup$
4
$\begingroup$

Look up arbitrary precision arithmetic. You can store the "digits" of a number in a variable sized data structure, like a linked list.

Several languages have arbitrary precision integers as their default integer type (Scheme and Mathematica come to mind). Other languages provide arbitrary precision integers through libraries.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.