I am basically trying to read a large file (about 10G) into a list of lines. The file contains a sequence of integers, something like this:
0x123456 0x123123 0x123123 .....
I used the method below to read the default files for my code base, but in this case it turns out to be slow (~ 12 minutes)
let lines_from_file (filename : string) : string list = let lines = ref [] in let chan = open_in filename in try while true; do lines := input_line chan :: !lines done; [] with End_of_file -> close_in chan; List.rev !lines;;
I think I need to read the file in memory and then split them into lines (I use a 128G server, so this should be good for the memory space). But I still do not understand if OCaml provides such a tool after searching for documents here .
So here is my question:
Given my situation, how to quickly view files in a list of strings?
How about using stream ? But I need to configure the appropriate application code, and this may cause some time.
source share