caching - How to disable Operating System(Ubuntu) cache in C program -


as far know, can disable os cache through use open() o_direct. how if willing use fopen() instead of open()?

i think due alignment requirements of o_direct flag it's not possible (see that question). f...() - io family uses internal buffer cache io operation , don't think standard implementation align buffer appropriately.

edit

for special purposes, think of 2 non-portable solutions:

  1. if sure, file system doesn't require special alignment, use fdopen():

    int fd = open( ....., o_wronly|o_direct ); file *fp = fdopen( fd, "w" ); 
  2. if working on linux only, using fopencookie() solution: use cookie transort 'real' fd open() , provide write function copies data appropriately aligned buffer , calls write() (i have never used fopencookie(), think worth trying if using non-standard gnu extension isn't nogo)

in both cases aware f-...() i/o functions still internal buffering real write()s may not occur before call fflush() or fclose()


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -