I have a file with 200mb, the file with following format
each line is a spaced 0,1,2,3 integer.
0 1 2 0 1 3…
So, if I want to read this file into memory, should I be using array, using Vector<Integer>? or using ByteArray? or String?
How can I estimate the memory cost, so that can I set the java heap size appropriately? Would 256mb be enough?
For String size x 2 – String use char for each byte (you can set virtual machine flag to use byte)
For List – count how many integer. For each integer it create one pointer to int (4 bytes or 8 bytes dependence on platform – you can set jvm option to use 32 bit address on 64 bit machine
-XX:+UseCompressedOops)Number of integers x ((size of one Integer) + (pointer to Integer in list)) = 2 * (number of integers) * (size of one pointer)
ByteBuffer – the same size like file
The best solution is primitive array – byte, short or int. It dependents of integer precision. For byte you have (number of int) bytes – can be less than file size.