Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is actually intended to <em>save</em> memory (and time spent creating objects). A program which uses BigIntegers is likely to have many copies of the same numbers, by storing just one instance of BigInteger(1), you can have hundreds of thousands of references to the number, but only have to create one object.</p> <p>It's worth noting that static initialization happens when a class is referenced, so programs which don't use BigInteger will not store this array. In programs which do use BigInteger, the worst case is you're storing 33 objects you don't have to, but in the best case scenario you're saving on the creation and storage of thousands of objects by simply referring to these constants.</p> <p>This is called the <a href="http://en.m.wikipedia.org/wiki/Flyweight_pattern" rel="nofollow">Flyweight Pattern</a>.</p> <p>Now, why store these specific constants, and not the exact objects used in the program? The latter would require storing every BigInteger used in the program in a hash table, and checking this table every time a new BigInteger is created, which is much more expensive in memory and computation time than the existing solution. You would also have to worry about concurrent modification of the table, so locking would be involved as well. Simply put, memoizing the exact objects used in the program is too expensive to be done by default. Some programs which re-use a lot of BigIntegers outside the range of -16 to 16 will implement this themselves.</p> <p>Small numbers usually occur much more often in programs, which is why these specific values were chosen to be memoized.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload