How to pre-allocation Harddisk space?

I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Interesting article.

It does provide code though. I did a quick scan and I saw that you will have
to P/invoke in order to use this feature, read the entire article and I'm
sure it will tell you how to do it
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Take also in count wheater the described technique is useful in a single
disk or in an array escenario
 
W

Willy Denoyette [MVP]

Did you actually read the document? It clearly states how you can
pre-allocate file space.

FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);

fs.SetLength(128 * 1024 * 1024);



But take care, don't expect it to be 'MUCH faster", it wont even be 'faster'
on a reasonable fragmented disk (few fragments).



Willy.




| According this
| http://research.microsoft.com/research/pubs/view.aspx?tr_id=841
|
| said, if you pre-allocation space for writing , it will be much faster,
| but how can i do this?
| Thank
 
C

Chi

Then , what will increase the speed?
Because I change my code from synchronous to Asynchronous but the speed
is slower than before.

My code is just sending file between two computer but it will open more
than 1 network stream and filestream to read write.

Now,I use fs.seek to locate different entry point to read write.
any suggestion? Thank
 
B

Barry Kelly

Willy Denoyette said:
Did you actually read the document? It clearly states how you can
pre-allocate file space.

FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);

fs.SetLength(128 * 1024 * 1024);

But take care, don't expect it to be 'MUCH faster", it wont even be 'faster'
on a reasonable fragmented disk (few fragments).

You'll end up with less fragments on average, however. The Cygwin 'cp'
utility (http://www.cygwin.com) ends up copying files in 4K chunks. A side
effect of that is large files copied with cp end up with hundreds of times
more fragments than the same files copied with (say) Windows Explorer.

Since I run cygwin bash as my main shell, I make frequent use of
http://www.sysinternals.com/Utilities/Contig.html to fix up files such as
the locatedb database after running updatedb.

If you're creating large files incrementally in .NET, using this will help
a lot to reduce fragmentation.

-- Barry
 
W

Willy Denoyette [MVP]

This is a totally different question isn't it?

First of all, what makes you thing it's too slow, what are your
expectations, how are you measuring things. Second, why don't you use what
is provided by Windows, that is, a network connection to a remote share that
can be used to copy files back and forth?
Two diffrent resources are involved when transfering (disk) file data from
one system to another over a network connection: a Disk resource (at both
ends) and the Network.
In general, the network is the slowest then comes the disk (write side), so
instead of trying to optimize the disk reading/writing you should start
looking at the network part.
What kind of connection do you have, what's the topology what's his speed?
What kind of transport protocol are you using? And how are you accessing it
from the application level (Sockets, Named pipes other). How about the
buffer sizes. And last but not least, what (and how) did you measured as
transfer rate?

Willy.



| Then , what will increase the speed?
| Because I change my code from synchronous to Asynchronous but the speed
| is slower than before.
|
| My code is just sending file between two computer but it will open more
| than 1 network stream and filestream to read write.
|
| Now,I use fs.seek to locate different entry point to read write.
| any suggestion? Thank
|
| Willy Denoyette [MVP] wrote:
| > Did you actually read the document? It clearly states how you can
| > pre-allocate file space.
| >
| > FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
| >
| > fs.SetLength(128 * 1024 * 1024);
| >
| >
| >
| > But take care, don't expect it to be 'MUCH faster", it wont even be
'faster'
| > on a reasonable fragmented disk (few fragments).
| >
| >
| >
| > Willy.
| >
| >
| >
| >
| > | > | According this
| > | http://research.microsoft.com/research/pubs/view.aspx?tr_id=841
| > |
| > | said, if you pre-allocation space for writing , it will be much
faster,
| > | but how can i do this?
| > | Thank
| >
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top