Create a continuous file using C #?

Is it possible to create a large (physically) contiguous file on disk using C #? It is preferable to use only managed code, but if this is not possible, an unmanaged solution will be evaluated.

+3
source share
5 answers

Writing a defragmenter?

It seems like after the defragmentation API you are still: -

http://msdn.microsoft.com/en-us/library/aa363911%28v=vs.85%29.aspx

The link is below because it seems like you missed the C # shell someone kindly produced.

http://blogs.msdn.com/b/jeffrey_wall/archive/2004/09/13/229137.aspx

+3
source

Any file you create will be logically contiguous.

, OS FS. () API -.

, , , , - : Length Position , .

+5

. , , , .

(ext2, FAT32 ..) , . , , , , .

int fileSize = 1024 * 1024 * 512;
FileStream file = new FileStream("C:\\MyFile", FileMode.Create, FileAccess.Write);
file.Seek(fileSize, SeekOrigin.Begin);
file.Close();
+2

, - , Windows API. - , "" , "" . , , , .

, . ReadFileScatter . WriteFileGather . , OVERLAPPED, .

, SQL Server, / , ​​ NT 4.0 SQL Server.

, , . , P/Invoke pinvoke.net, . , , , . # , . - , , .

contig.exe, , .

+1

,

The OS will do this in the background, I would make the file as large as you expect, so the OS will put it in contact. And if you need to grow the file, you will again grow by about 10% each time. This is similar to how the SQL server stores database files.

Open the opening FileStream that you open with the addition.

Example:

FileStream fwriter = new FileStream("C:\\test.txt", FileMode.Append,     FileAccess.Write, FileShare.Read);
0
source

Source: https://habr.com/ru/post/1789472/


All Articles