2 ms·
>why we read files using rewind, fseek, fread, and fwrite as if we were on a tape drive still Not sure about rewind (is it the same as fseek(0)?), but regardin
by coldtea 6y ago
>why we read files using rewind, fseek, fread, and fwrite as if we were on a tape drive still
Not sure about rewind (is it the same as fseek(0)?), but regarding fseek, fread, and fwrite, they seem compatible with the abstract idea of "file as a series of bytes" and not particularly tied to the "stored on a tape drive" part.
What would be a modern era API for file reading, moving inside, and writing, that doesn't carry the "tape drive" heritage as implied by the author?
- lapinot 6y agoI would guess mmap: view it as a char[]. With flash storage and ubiquitous page-cache the read/write/seek reading-needle abstraction is kind of moot. Triggering a syscall on seek when you could just pass an offset to every read is a bit disturbing. It's probably because of this that most languages provide buffered readers even tho the underlying file is already buffered by the kernel.
- alisonkisk 6y agoRight. The opposite of random access is sequential access. Tapes are extremely sequential, HDD are less sequential, SSDs are barely sequential, and memory mapped files are almost entirely non-sequential