Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are they holding this many instances(33) even before being asked for? Where did they get the number 16 from?
    primarykey
    data
    text
    <p>When I was studying about static blocks , I wanted to see its usage in java source code . so I referred java.math.BigInteger.java . The static block there was like this </p> <pre><code>/** * Initialize static constant array when class is loaded. */ private final static int MAX_CONSTANT = 16; private static BigInteger posConst[] = new BigInteger[MAX_CONSTANT+1]; private static BigInteger negConst[] = new BigInteger[MAX_CONSTANT+1]; static { for (int i = 1; i &lt;= MAX_CONSTANT; i++) { int[] magnitude = new int[1]; magnitude[0] = i; posConst[i] = new BigInteger(magnitude, 1); negConst[i] = new BigInteger(magnitude, -1); } } </code></pre> <p><a href="https://upsource.jetbrains.com/lib/view/jdk7u10/java/math/BigInteger.java;nav:36548:36556%3afocused" rel="nofollow">static block code in code browser </a></p> <p>From this I am getting a sense that they are creating 33 BigInteger instances and holding it in posConst and negConst . Then later when people call valueOf in <a href="https://upsource.jetbrains.com/lib/view/jdk7u10/java/math/BigInteger.java;nav:35145:35152%3afocused" rel="nofollow">BigInteger.java:valueOf</a></p> <p>if value is between -16 to 16 they take from posConst and negConst and give . If it is beyond this range they create new instance .</p> <p>I can understand that they are holding instances to give it readily if user asks one among that list . On what basis or probability are they holding 33 instances . Is it not a waste of memory . Why not create when user asks and only that particular instance . </p> <p>I cannot understand the trade off attained in this logic . Please help . Am I going wrong in understanding this code . If so please help .</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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