How to represent a random-access text file in memory (C) -
I am working on a project where I need to read the text in the memory (source) file and do the random work Enabling may enter (for example, reclaim the address related to row 3, column 15).
I would like to know that there is a definite method of doing this, or work of data structures that are especially good. I should be able to use one (maybe amortized) consecutive time I am working in C, but if it is worth it then I am ready to implement high level data structures.
My first idea was to go from a linked list of big buffers, in which the color data data would be file. I will also create an array, whose index is similar to line numbers and start of the content line. This array will be allocated again on the requirement.
Subsidy Question: Does anyone get the average size of a source file? I was amazed at the fact that it is not on Google.
To clarify: I am worried about the files are the source files, so their size should be manageable, they should not be modified. And variable length (some expectations are expected) in lines. The problem I'm mostly working on needing a readable file representation, but I'm very interested in digging the problem to solve Conlusion:. A very interesting discussion of the data structures used to maintain a file (with support / support in inserting paper / delete support). If you just need to read, just get the size of the file, read it in memory with Fred (), then you have to maintain a dynamic array that maps the line in line Number indicator of first character (index). Below someone suggested to build this array lazily, which seems to be a good idea in many cases. After the I do not have enough question that the question is here, but "I think the file is stored Both "and" How do I index it "both look a bit. Since you need to have random access to the contents of the file, you are probably advised to archive the file, unless you are tight in place of the address. I do not think you will be able to find at the end of the line once to avoid a linear pass through the file. As you said, you can make pointers for the beginning of each line if you are not sure how many indices you want, then make it lazy (on demand). You can also store this index on disk (as offset, not pointers) if you need it on subsequent run. You can infer the size of the index based on file size and expected line length.
Comments
Post a Comment