int open(char* filename);
int write(char* buf, int size_t); int close();
size_t gbytesWritten() { return bytes_written / 1000 / 1000 / 1000; } private:
int fd;
size_t bytes_written; };
int DirectFile::open(char* filename) { int ret = 0;
fd = ::open(filename, O_DIRECT O_WRONLY, S_IRUSR S_IWUSR S_IRGRP); if( fd ==
ret =
}
bytes_written = 0; return ret;
}
int DirectFile::write(char* buf, int bufsize) {
int written = pwrite(fd, buf, bufsize, bytes_written); if( written >= 0 )
bytes_written += written; return written;
}
int main( int argc, char **argv) { char* buf;
int ret = 0; enum { numpages = 256, };
int pagesize = getpagesize();
int bufsize = pagesize * numpages;
if( ret = posix_memalign((void**)&buf, pagesize, bufsize) ) { cerr << "Memalign failed" << endl;
exit(ret);
}
memset(buf, 0xaa, bufsize); DirectFile file;
if( file.open(FILENAME) ) {
cerr << "Open of " << FILENAME << " failed" << endl;