python - Default buffer size for a file on Linux -


the documentation states default value buffering is: if omitted, system default used. on red hat linux 6, not able figure out default buffering set system.

can please guide me how determine buffering system?

since linked 2.7 docs, i'm assuming you're using 2.7. (in python 3.x, gets lot simpler, because lot more of buffering exposed @ python level.)

all open (on posix systems) call fopen, , then, if you've passed buffering, setvbuf. since you're not passing anything, end default buffer fopen, c standard library. (see the source details. no buffering, passes -1 pyfile_setbufsize, nothing unless bufsize >= 0.)

if read glibc setvbuf manpage, explains if never call of buffering functions:

normally files block buffered. when first i/o operation occurs on file, malloc(3) called, , buffer obtained.

note doesn't size buffer obtained. intentional; means implementation can smart , choose different buffer sizes different cases. (there bufsiz constant, that's used when call legacy functions setbuf; it's not guaranteed used in other case.)

so, does happen? well, if @ glibc source, calls macro _io_doallocate, can hooked (or overridden, because glibc unifies c++ streambuf , c stdio buffering), ultimately, allocates buf of _io_bufsize, alias platform-specific macro _g_bufsize, 8192.

of course want trace down macros on own system rather trust generic source.


you may wonder why there no documented way information. presumably it's because you're not supposed care. if need specific buffer size, set 1 manually; if trust system knows best, trust it. unless you're working on kernel or libc, cares? in theory, leaves open possibility system smart here, picking bufsize based on block size file's filesystem, or based on running stats data, although doesn't linux/glibc, freebsd, or os x other use constant. , that's because doesn't matter applications. (you might want test out yourself—use explicit buffer sizes ranging 1kb 2mb on buffered-i/o-bound script , see performance differences are.)


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -