The mmap function allows you to quickly map a file into demand paged address space. With the MAP_PRIVATE flag one could even parse the strings in place like in my code without affecting the underlying file. I didn't do this in my code because I needed to read the whole file anyway to set up the row and column counts as well as the matrix of string pointers.Don't forget, you can also treat the file on disk as an "array". Given the row and column index you could read the file and discard everything until you reach the desired element.
It will be relatively slow, but doesn't need a lot of memory. Really depends on what constraints you are working with.
You can use another language if you like, but as ejolson says, you often don't get a choice.
I think mmap may not be as portable as fopen, fread and fclose.
https://linux.die.net/man/2/mmap
Hm. It seems I forgot fclose in my program.
Statistics: Posted by ejolson — Wed Feb 07, 2024 11:44 pm