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:
if sure, file system doesn't require special alignment, use
fdopen():int fd = open( ....., o_wronly|o_direct ); file *fp = fdopen( fd, "w" );- if working on linux only, using fopencookie() solution: use 
cookietransort 'real' fdopen(), provide write function copies data appropriately aligned buffer , callswrite()(i have never usedfopencookie(), 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
Post a Comment