diff --git a/qse/include/qse/cmn/fio.h b/qse/include/qse/cmn/fio.h index 0b7e5d2a..ce62459f 100644 --- a/qse/include/qse/cmn/fio.h +++ b/qse/include/qse/cmn/fio.h @@ -59,9 +59,10 @@ enum qse_fio_open_flag_t QSE_FIO_NOSHRD = (1 << 24), QSE_FIO_NOSHWR = (1 << 25), - /* for WIN32 only. harmless(no effect) when used on other platforms */ + /* hints to OS. harmless(no effect) when used on unsupported platforms */ QSE_FIO_RANDOM = (1 << 26), /* hint that access be random */ - QSE_FIO_SEQUENTIAL = (1 << 27) /* hint that access is sequential */ + QSE_FIO_SEQUENTIAL = (1 << 27), /* hint that access is sequential */ + QSE_FIO_NOCACHE = (1 << 28) /* no system I/O cache */ }; enum qse_fio_std_t diff --git a/qse/lib/cmn/fio.c b/qse/lib/cmn/fio.c index bd129601..73517305 100644 --- a/qse/lib/cmn/fio.c +++ b/qse/lib/cmn/fio.c @@ -155,6 +155,8 @@ int qse_fio_init ( flag_and_attr |= FILE_FLAG_RANDOM_ACCESS; if (flags & QSE_FIO_SEQUENTIAL) flag_and_attr |= FILE_FLAG_SEQUENTIAL_SCAN; + if (flags & QSE_FIO_NOCACHE) + flag_and_attr |= FILE_FLAG_NO_BUFFERING; handle = CreateFile ( path, desired_access, share_mode, @@ -369,6 +371,20 @@ int qse_fio_init ( if (handle == -1) return -1; + /* set some file access hints */ + #if defined(POSIX_FADV_RANDOM) + if (flags & QSE_FIO_RANDOM) + posix_fadvise (handle, 0, 0, POSIX_FADV_RANDOM); + #endif + #if defined(POSIX_FADV_SEQUENTIAL) + if (flags & QSE_FIO_SEQUENTIAL) + posix_fadvise (handle, 0, 0, POSIX_FADV_SEQUENTIAL); + #endif + #if defined(POSIX_FADV_DONTNEED) + if (flags & QSE_FIO_NOCACHE) + posix_fadvise (handle, 0, 0, POSIX_FADV_DONTNEED); + #endif + #endif if (flags & QSE_FIO_TEXT)