1

Size of the old region is controlled using -XX:NewRatio parameter, how would I determine its value in runtime? Thanks in advance!

Update I haven't been attentive enough, the question is basically a copy of How to get vm arguments from inside of java application?. I would delete it but there is an interesting discussion below so I will do it a little bit later when it is finished

4

1 回答 1

1

OK, so, if I understand correctly, you have a very large file, several GB large, full of ints, and these ints are stored in big endian.

My proposal is the following: create a class implementing List<Integer> over such a large file, and use Collections.sort().

That is:

  • you take as an argument the file you need sorted;
  • you map that file in memory;
  • you implement the List interface;
  • you let Collections.sort() do the job.

Once Collections.sort() is done, you just .force() the channel from which you obtained the MappedByteBuffer. If no I/O error, you're good to go, replace the original file.

Yeah, that is quite some work, but it is doable. Demo code on demand.

NOTE: FileChannel.map() is limited; you may have to create several mappings. I'd recommend splitting into 1 GB mappings. This will quite complicate the implementation of .subList(), admittedly. Also, be aware that you'll only be able to address up to Integer.MAX_VALUE ints; which means your file cannot be larger than ((1 << 31 - 1) << 2). 1 << 33 is 8 GB.

于 2013-07-13T18:40:38.993 回答