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.
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.