It could be generally stated: how do you implement a method byte[] get(offset, length)
for a memory-mapped file that is bigger than 2GB in Java.
With context:
I'm trying to read efficiently files that are bigger than 2GB with random i/o. Of course the idea is to use Java nio and memory-mapped API.
The problem comes with the limit of 2GB for memory mapping. One of the solutions would be to map multiple pages of 2GB and index through the offset.
There's a similar solution here:
Binary search in a sorted (memory-mapped ?) file in Java
The problem with this solution is that it's designed to read byte while my API is supposed to read byte[]
(so my API would be something like read(offset, length)
).
Would it just work to change that ultimate get()
to a get(offset, length)
? What happens then when the byte[]
i'm reading lays between two pages?
No, my answer to Binary search in a sorted (memory-mapped ?) would not work to change
get()
toget(offset, length)
because of the memory mapped file array boundary, like you suspect. I can see two possible solutions: