有时候,读写文件并不想要使用系统缓存(page cache),此时 direct 文件读写就派上了用场,使用方法:

 

(1)打开文件时,添加O_DIRECT参数:

需要定义_GNU_SOURCE,否则找不到O_DIRECT宏定义

示例片段:

#define _GNU_SOURCE
  
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
 
int fd = open("test.out", O_RDWR | O_CREAT | O_DIRECT, 0644);
View Code  

相关文章:

  • 2018-02-02
  • 2021-12-04
  • 2022-01-01
  • 2021-12-02
  • 2021-08-23
  • 2021-11-11
  • 2022-01-29
猜你喜欢
  • 2021-09-27
  • 2021-10-22
  • 2022-12-23
  • 2021-12-24
  • 2021-11-21
  • 2021-09-27
  • 2021-09-27
相关资源
相似解决方案