Is there any reasons to not use "mmap" to read files?
Patrick Schluter
Patrick.Schluter at bbox.fr
Sun Feb 13 10:57:00 UTC 2022
On Sunday, 13 February 2022 at 03:01:09 UTC, Ali Çehreli wrote:
> On 2/12/22 05:17, rempas wrote:
>
> > a system call every single time
>
> I have a related experience: I realized that very many ftell()
> calls that I were making were very costly. I saved a lot of
> time after realizing that I did not need to make the calls
> because I could maintain a 'long' variable to keep track of
> where I was in the file.
>
> I assumed ftell() would do the same but apparently not.
>
ftell() and fseek() use a syscall but also trigger that the next
stdio read call (fgets, fgetc, fread, fscanf etc.) will
systematically read its internal buffer again. If you make an
itrace on an app with a fseek (ftell is often implement by using
a relative seek of 0 call) yo will see something like
That's why one should avoid using seek when working with buffered
stdio.
More information about the Digitalmars-d
mailing list