简体   繁体   中英

How to speed up reading of a large OBJ (text) file?

I am using an OBJ Loader library that I found on the 'net and I want to look into speeding it up.

It works by reading an .OBJ file line by line (its basically a text file with lines of numbers)

I have a 12mb OBJ file that equates to approx 400,000 lines. suffice to say, it takes forever to try and read line by line.

Is there a way to speed it up? It uses a BufferedReader to read the file (which is stored in my assets folder)

Here is the link to the library: click me

Just an idea: you could first get the size of the file using the File class, after getting the file:

File file = new File(sdcard,"sample.txt");
long size = file.length();

The size returned is in bytes, thus, divide the file size into a sizable number of chunks eg 5, 10, 20 etc with a byte range specified and saved for each chunk. Create byte arrays of the same size as each chunk created above, then "assign" each chunk to a separate worker thread, which should read its chunk into its corresponding character array using the read(buffer, offset, length) method ie read "length" characters of each chunk into the array "buffer" beginning at array index "offset". You have to convert the bytes into characters. Then concatenate all arrays together to get the final complete file contents. Insert checks for the chunk sizes so each thread does not overlap the others boundaries. Again, this is just an idea, hopefully it will work when actually implemented.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM