硬盘空间连续地 - NTFS [英] contiguously space on hard disk - NTFS

查看:160
本文介绍了硬盘空间连续地 - NTFS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于NTFS FS文件分配方法。

My question is about file allocation methods on NTFS Fs.

我有两个主要问题 -

I have two main questions -


  1. 当我创建在NTFS文件时,将它连续存储的物理硬盘上?

  2. 如果不是 - 是有办法创造它,这样当我写它的数据是连续存储(硬盘)的文件?喜欢的东西在数据库范围。

  3. 如果存在这样的文件 - 有什么办法中读取数据它(用C read系统调用)
    串/块。什么是最大的一堆大小,我可以使用。

我试图让小型应用程序的简单的基于文件的数据库,并想使我的数据库的文件中。出于性能原因,我需要让我的数据在连续的顺序在磁盘上,并在束阅读。 (我计划的mmap在我的应用程序文件)。

I am trying to make a simple file based DB for small applications and would like to make my db in the file. for performance reason i need to keep my data in contiguous order on the disk and read it in bunches. (I plan to mmap this file in my application).

推荐答案

OK,让我们回答逐点......

OK, so let's answer point by point...

问题1 当我创建在NTFS文件时,将它连续存储的物理硬盘上

问题是没有意义的。当你创建一个文件,NTFS将分配在MFT的空间,它需要跟踪的东西的元数据。小文件实际上可能适合该文件的MFT记录内 - 该居民文件,顾名思义,是连续的。如果文件将不适合在MFT内,则空间块被分配在必要并且它们可以是或可以不是连续的。一般来说,它不知道你的文件有多大,或者多少空间preallocate它 - 那么NTFS只会分配空间作为必要的,虽然可以通过调用的 SetEndOfFile 功能。但是,只提供了一个线索和难保该文件数据将存储在磁盘的连续区域。事实上,它应该是微不足道的说服自己,即使文件系统进行实时碎片整理,也比不上*的保证的,自由空间将作为磁盘地址的单一连续的块。

The question makes no sense. When you create a file, NTFS will allocate the space in the MFT for the metadata it needs to track things. Small files may actually fit inside the MFT record for the file - such resident files are, by definition, contiguous. If a file won't fit inside the MFT, then blocks of space are allocated as necessary and they may or may not be contiguous. Generally speaking, it doesn't know how big your file will be, or how much space to preallocate for it - so NTFS will just allocate space as necessary, although you can give it a hint by calling the SetEndOfFile function. But that provides only a hint and no guarantee that the file data will be stored in a contiguous area of the disk. In fact, it should be trivial to convince yourself that even if the filesystem performs real-time defragmentation, it can never *guarantee that the free space will be available as a single, contiguous block of disk addresses.

问题2 如果不是 - 是有没有办法在其中创建这样的一个文件,当我写它的数据是连续存储(在硬盘上)?喜欢的东西在数据库中。扩展

为什么你认为这是一个重要的问题?您通常不应该关心文件系统如何存储你的数据;你应该只关心它存储数据的事实。你可能会认为访问该不是连续存储将是慢的文件,但这并不是必然,是这样的;高级缓存算法和由O prefetching / S经常会彻底消除任何放缓。如果您关注的是性能,那么你有没有的实际硬盘数据的显示了碎片的文件系统是一个问题?如果是这样,正确的做法是要么使用一个不同的文件系统或文件系统没有在所有。

Why do you think this is an important concern? You generally shouldn't care how the filesystem stores your data; you should only care about the fact that it does store the data. You may think that accessing a file that's not stored continuously would be slower, but that may not, necessarily, be the case; advanced caching algorithms and prefetching by the O/S will often eliminate any slowdown completely. If your concern is performance, then do you have actual hard data that shows that fragmentation by the filesystem is an issue? If so, the correct approach is to either use a different filesystem or no filesystem at all.

问3 如果存在这样的文件 - 有什么办法来读取它的数据(用C read系统调用)的串/块。什么是最大的一堆大小,我可以使用。

该空调系统调用(比如 FREAD )不知道NTFS,条块分割,串和块。他们只知道如何阅读从指定的文件句柄请求的字节数,并把数据放到你提供的缓冲区。您可以指定你想要的,真任意大小,虽然C库将调用O / S和文件系统特定的API块大小的倍数来读取数据,这是实现定义。

The C system calls (like fread) don't know about NTFS, fragmentation, "bunches" and blocks. All they know is how to read the requested number of bytes from the specified file handle and put the data into a buffer that you supply. You can specify any size that you want, really, although the C library will call O/S and filesystem specific APIs to read data in multiples of the block size, which is implementation defined.

这篇关于硬盘空间连续地 - NTFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆