2

I know fgetpos/fsetpos are used for returning to a file position.

But if I accessed that position with fseek to begin with, is it more efficient to use fgetpos/fsetpos to return later, or just the same fseek again?

Jespoke
  • 99
  • 4
  • On which system? My guess would be that on most or all systems that implement these functions, the difference, if any, is negligible. But to know for sure, you need to actually measure. Or perhaps read the source code, when it is available. – Thomas Padron-McCarthy Dec 23 '17 at 17:28
  • I'm on Windows, but a groupmate is on Unix, so I was looking for something general. – Jespoke Dec 23 '17 at 18:32

1 Answers1

3

Is fgetpos/fsetpos any faster than fseek?

For general file positioning, fseek()/ftell() are limited to files sizes about LONG_MAX. fsetpos()/fgetpos() are designed to handle the file system's file sizes.

For large files, fseek()/ftell() are not an option. @Thomas Padron-McCarthy

When coding C99 onward, robust code uses fsetpos()/fgetpos() in lieu of a minor optimization that may of may not be present using the more limited fseek()/ftell().

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256