1

What I want to do is to shift a large array of bytes to 10 higher indexes. I know I can easily do it this way:

byte [] bArray = new byte [1000000];
System.arraycopy(bArray, 0 , bArray, 10, 900000 );

however, in our specific code we will be doing that every time we call a method, and that method is gonna be called a million times in our code. That makes us worry about memory leak as that is going go put lots of work on JVM to reallocate the heap over and over again in high frequency.

4

1 回答 1

5

System.arraycopy 使用起来非常安全——它不会导致“泄漏”或以某种方式损坏数组。这也是在 Java 中移动大量数据的最有效方式。

System.arraycopy 与堆管理毫无关系——它不分配任何额外的存储空间。

也就是说,移动大量数据并不是特别有效——它“弄脏”了缓存,导致性能下降。值得考虑不同的设计。

于 2013-07-16T01:47:42.347 回答