Basically, I would like to read a binary file in blocks of 4096 bytes. And I know to myself that using f.read(X) makes a system call which would be slow. And since i can't read the whole file and store it in binary because those files are gigabytes in size: I decide to read in blocks of 4096.
But now, I am stumped: I want to know what it means to f.read(4096).... Does it really call a system call once to get the successive 4096 bytes from the file or does it actually call a system call that gets 1 byte from the file 4096 times?
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Python3: what does it mean to f.read(4096)?
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
Re: Python3: what does it mean to f.read(4096)?
Python3: what does it mean to f.read(4096)?
This is one, it might help explain,if not there are lots more:
http://stackoverflow.com/questions/6787 ... nd-save-it
This is one, it might help explain,if not there are lots more:
http://stackoverflow.com/questions/6787 ... nd-save-it
"What we expect you have already Done"
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
Re: Python3: what does it mean to f.read(4096)?
It looks like You have completely no idea of what You're actually want to do...suttiwit wrote:Basically, I would like to read a binary file in blocks of 4096 bytes. And I know to myself that using f.read(X) makes a system call which would be slow.
It seems that You've heard *something* about memory pages, but unfortunately You have completely no idea where the 4Kb buffer size comes from... just a disaster... (it's a false assumption that the memory page is 4096 bytes wide)
You should know (and this is the actual answer) that there's a technique, which was developed far before the UNIX started to exist, called: mmap - which allows to access any kind of data stored in a file just like if they were an array of bytes - or, in more advanced cases - a structure...
Regards
Odi profanum vulgus
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
Re: Python3: what does it mean to f.read(4096)?
For those that do not know what "mmap" is :
http://man7.org/linux/man-pages/man2/mmap.2.html
and
https://en.wikipedia.org/wiki/Mmap
Also
------------------
More, on how to to read a binary file in blocks of 4096 bytes
http://man7.org/linux/man-pages/man2/mmap.2.html
and
https://en.wikipedia.org/wiki/Mmap
Also
Code: Select all
$ man Mmap
More, on how to to read a binary file in blocks of 4096 bytes
"What we expect you have already Done"
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?