不使用系统缓存的文件读写操作
最近小弟的项目需要最快的文件读写操作。查阅资料发现非缓存的文件读写操作速度最快,也就是在CreateFile的时候制定FILE_FLAG_NO_BUFFERING操作。但MSDN的说明让我很疑惑:
这个标志的使用有前提
An application must meet certain requirements when working with files
opened with FILE_FLAG_NO_BUFFERING:
当使用FILE_FLAG_NO_BUFFERING打开文件进行工作时,程序必须达到下列要求:
File access must begin at byte offsets within the file that are
integer multiples of the volume's sector size.
文件的存取开头的字节偏移量必须是扇区尺寸的整倍数.
File access must be for numbers of bytes that are integer
multiples of the volume's sector size. For example, if the sector
size is 512 bytes, an application can request reads and writes of
512, 1024, or 2048 bytes, but not of 335, 981, or 7171bytes.
文件存取的字节数必须是扇区尺寸的整倍数.例如,如果扇区尺寸是512字节
程序就可以读或者写512,1024或者2048字节,但不能够是335,981或者7171
字节.
buffer addresses for read and write operations must be sector
aligned(aligned on addresses in memory that are integer multiples
of the volume's sector size).
进行读和写操作的地址必须在扇区的对齐位置,在内存中对齐的地址是扇区
尺寸的整倍数.
我的问题在于,如果读写的字节数都是扇区尺寸的整数倍,那么对于那些非整数倍尺寸的文件怎么进行操作呢?例如扇区尺寸是512Byte,而这个文件是1025Byte,需要三个扇区才能装下,那么我读3个扇区显然超过了这个文件的大小,写入的时候就变成了512*3Byte了。~~~
这种情况怎么处理呢?
或者能不能提供不使用系统缓存的文件读写操作的例子呢?谢谢!