octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #54100] fread using SKIP larger than zero is e


From: Dan Sebald
Subject: [Octave-bug-tracker] [bug #54100] fread using SKIP larger than zero is extremely slow
Date: Tue, 12 Jun 2018 16:16:14 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

Follow-up Comment #3, bug #54100 (project octave):

You may be right, meaning that this is one of those situations where it would
involve implementing the two approaches and comparing.  It might even be
system dependent.

What you describe, i.e., first reading in a block of data, is certainly
something I've done in other applications and it is efficient.  It's
especially useful when having to access the data more than once, say for
filtering a big block of data, level crossing, etc.  I often do this in a
"ping-pong" buffer kind of design.

If something more sophisticated isn't needed though, keep in mind that the C
library is most likely already doing just what you describe.  It's buffered
I/O, so behind the curtain it is reading in a block of data and keeping a file
pointer into that buffer (not fetching every new bit of data from disk with
every fread()).  Doing that buffering a second time just adds a little more,
but it is only a small addition because the C routines are optimized to bring
in a block of bytes.  That's why I think "seek (skip, SEEK_CUR);" is probably
pretty efficient; it's just advancing the pointer in the C library.  Whereas
"seek (0, SEEK_END);" is inefficient because it means jumping to the end of
the file, streaming a whole new bunch of data from disk into the cache.

So in summary, it depends but either approach will be much better than moving
the file pointer to the EOF and back before every block read.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?54100>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]