java - Memory map directly to string -


i have file i'm mapping memory via 'filechannel.map()'. seems bit odd when reading string following:

1) read int string length 2) allocate byte[length] object 3) use .get read length bytes 4) convert byte[] string 

now know c++ background memory mapped files given user pointers memory. there way skip using byte array , have string conversion go right off mapped memory?

i suggest:

mappedbytebuffer mapped = filechannel.map(mode, position, size); string s = new string(mapped.array()); 

it possible use mapped.ascharbuffer() , chars way.


Comments