Documentation
¶
Overview ¶
This is library for the Go language to enable use of Direct IO under all supported OSes of Go.
Direct IO does IO to and from disk without buffering data in the OS. It is useful when you are reading or writing lots of data you don't want to fill the OS cache up with.
Instead of using os.OpenFile use directio.OpenFile
in, err := directio.OpenFile(file, os.O_RDONLY, 0666)
And when reading or writing blocks, make sure you do them in chunks of directio.BlockSize using memory allocated by directio.AlignedBlock
block := directio.AlignedBlock(BlockSize)
_, err := io.ReadFull(in, block)
Index ¶
Constants ¶
const ( // Size to align the buffer to AlignSize = 4096 // Minimum block size BlockSize = 4096 // Extra flags for windows FILE_FLAG_NO_BUFFERING = 0x20000000 FILE_FLAG_WRITE_THROUGH = 0x80000000 )
Variables ¶
This section is empty.
Functions ¶
func AlignedBlock ¶
AlignedBlock returns []byte of size BlockSize aligned to a multiple of AlignSize in memory (must be power of two)
func OpenFile ¶
OpenFile is a modified version of os.OpenFile which sets the passes the following flags to windows CreateFile.
The FILE_FLAG_NO_BUFFERING takes this concept one step further and eliminates all read-ahead file buffering and disk caching as well, so that all reads are guaranteed to come from the file and not from any system buffer or disk cache. When using FILE_FLAG_NO_BUFFERING, disk reads and writes must be done on sector boundaries, and buffer addresses must be aligned on disk sector boundaries in memory.
FIXME copied from go source then modified
Types ¶
This section is empty.