怎么换算的啊?进制数之间可以转换,为什么两个不同计量单位之间也可以转换啊?
代码如下:
import java.nio.*;
import java.nio.channels.*;
import java.io.*;
import static net.mindview.util.Print.*;
public class LargeMappedFiles {
static int length = 0x8FFFFFF; // 128 MB
public static void main(String[] args) throws Exception {
MappedByteBuffer out =
new RandomAccessFile("test.dat", "rw").getChannel()
.map(FileChannel.MapMode.READ_WRITE, 0, length);
for(int i = 0; i < length; i++)
out.put((byte)'x');
print("Finished writing");
for(int i = length/2; i < length/2 + 6; i++)
printnb((char)out.get(i));
}
}
PHP中文网2017-04-17 17:37:27
It should be a clerical error. You can use a calculator to calculate that 128MB is 0x8000000, or you can test it yourself and the generated test.data will be 143MB
RandomAccessFile randomAccessFile = new RandomAccessFile("test.data", "rw");
FileChannel channel = randomAccessFile.getChannel();
ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 0x8FFFFFF);
大家讲道理2017-04-17 17:37:27
Even if the unit of 0x8FFFFFF is B, it is about 144MB after conversion. 0x8000000 B is equal to 128MB
PHP中文网2017-04-17 17:37:27
It should be that the code and comments are out of sync. For example, it was originally 0x8000000, which is 128MB. Later, it was changed to 0x8FFFFFFF for some reason, but I forgot to change the comment. Or simply a clerical error. This feels like a typical "useless" comment.
ringa_lee2017-04-17 17:37:27
This seems to be a problem about conversion between complement code, inverse code and source code.