git.net

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

Understand workflow about reading and writing files in Python


When you said "C-runtime buffered I/O", are you talking about Standard I/O
in C (FILE * object)? AFAIN, In CPython, we didn't use Standard I/O, right?

Dennis Lee Bieber <wlfraed at ix.netcom.com> ?2019?6?25??? ??12:48???

> On Mon, 24 Jun 2019 15:18:26 +1200, DL Neil
> <PythonList at danceswithmice.info> declaimed the following:
>
>
> >
> >However, the OpSys may have read considerably more data, depending upon
> >the device(s) involved, the application, etc; eg if we ask for 2 bytes
> >the operating system will read a much larger block (or applicable unit)
> >of data from a disk drive.
> >
>
>         Depending upon implementation, there could be layers of buffers
> involved...
>
>         Python application requests, say, 50 bytes using a "buffered I/O"
> file
> object. That file object may invoke a C-runtime buffered I/O call that
> requests whatever the C-runtime buffer-size is -- say a 512 byte sector.
> That request goes to a low-level device driver for a file system/device
> that does I/O in 4KB clusters. So the first read results in the OS reading
> 4KB into a buffer, and passing 512 bytes to the C-call, which then returns
> 50 bytes to the Python layer.
>
>         The second read for 50 bytes is satisfied from the remaining bytes
> in
> the C-runtime sector buffer. The 11th read of 50 bytes will get 12 bytes
> from the sector, and then the C-runtime has to request the next sector from
> the OS, which is satisfied from the file system cluster buffer. After the
> 8th sector is processed, the next request results in the OS going to disk
> for the next cluster.
>
>
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfraed at ix.netcom.com
> http://wlfraed.microdiversity.freeddns.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>