Determine the optimal size for array with respect to the JVM's memory granularity

前端 未结 2 582
别跟我提以往
别跟我提以往 2021-01-05 13:12

When creating the backing array for (e.g.) a collection, you do not really care about the exact size of the array you create, it only needs to be at least as large as you ca

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-05 13:51

    When dynamically sized collections increase the size of their backing array, they do not add a small amount to its size, they increase in proportion. Doubling is a common choice. They do this because it gives better performance. The tiny adjustment you suggest would not be worth the effort.

提交回复
热议问题