fastest way to load NON-readonly files.

C

chad kline

i have searched around for an answer to this question,
but haven't found a satisfactory answer.

i understand things like mmap(2) can be used to quickly load
a file - but it seems to be a function for "read-only" situtations.
it doesn't appear to be useful in situations where editing must be
done on the loaded file.

the next fastest method (based on my searches) seemed to be
a fread(3)/read(2) loop. however, malloc(3)'s seems to slow
this down to an incredible extent.

--

the best way i could think to load a file for editing was
to load a file into a pointer to line pointers (each line
malloc'd for). however, on files with 10's and 100's of
thousands of lines, this process takes FOREVER. i am
reading line 150,000 half an hour later on a 500MHz
FBSD machine. there's actually 3 malloc() calls per line.
1 to increase the allocation to a pointer to line lengths,
1 to increase the allocation to pointers to lines,
and 1 to allocate space for the actual line.

i know there's a better way - but what is it?
my 'joe editor' can load a 20MB file in 1-2 seconds.
i can't figure out how to do it in under an hour! heh.
(unfortunately, "joe" code is undreadable!).

thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top