简体   繁体   English

RandomAccessFile:循环写入(字节)或写入(字节数组),哪个更有效?

[英]RandomAccessFile: write(byte) in a loop or write(byte array), whats more effiecient?

I am wondring what is more efficient should I use a for loop that invokes write with each byte x times, or I should have an array that will contain my data and write it with write(byte array)?我想知道我应该使用一个for循环来调用每个字节x次的write,或者我应该有一个包含我的数据的数组并用write(字节数组)写入它,什么更有效? Basically the question is write(byte array) more efficient than subsquent calls for write(byte) in a loop.基本上,问题是 write(byte array) 比在循环中对 write(byte) 的后续调用更有效。 I am programing in java and using RandomAccessFile.我正在 java 中编程并使用 RandomAccessFile。

Writing a byte array is always going to be quicker than repeated calls to write one byte at a time.写入字节数组总是比重复调用一次写入一个字节要快。 There's much less overhead (method calls, IO).开销要少得多(方法调用、IO)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM