fastest way to load NON-readonly files.

Discussion in 'C Programming' started by chad kline, Aug 12, 2003.

  1. chad kline

    chad kline Guest

    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.
    chad kline, Aug 12, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chad kline

    fast way to read NON-readonly files

    chad kline, Aug 12, 2003, in forum: C Programming
    Replies:
    1
    Views:
    314
    Thomas Matthews
    Aug 12, 2003
  2. utab
    Replies:
    7
    Views:
    386
  3. Dun Peal
    Replies:
    2
    Views:
    261
    Carl Banks
    Oct 18, 2010
  4. Jonathan Hyatt
    Replies:
    1
    Views:
    1,916
    Jonathan Hyatt
    Jun 8, 2004
  5. TKapler
    Replies:
    1
    Views:
    86
Loading...

Share This Page