Big empty file creation

Z

Zhukov Pavel

I need to creat an empty file, over 10GB size.
Which way is fastest in file creation?
 
R

Robert Klemme

use IO#sysseek followed which a IO#seekwrite

But note that this will not work on all OS in case the file must be
allocated. Seeking likely creates a sparse file.

Another approach is to use dd like

dd if=/dev/zero of=your_file bs=1048576 count=10240

That's probably as fast as it gets if you need blocks actually allocated
to the file.

Kind regards

robert
 
Z

Zhukov Pavel

But note that this will not work on all OS in case the file must be
allocated. Seeking likely creates a sparse file.

Another approach is to use dd like

dd if=/dev/zero of=your_file bs=1048576 count=10240

That's probably as fast as it gets if you need blocks actually allocated to
the file.

Kind regards

robert

i can't use dd, cause i want a cross-platform application
 
E

Eleanor McHugh

I need to creat an empty file, over 10GB size.
Which way is fastest in file creation?


Pick a value of x that's a multiple of 512 bytes as this will match
your data writes to the OS's disk cache. This may or may not gain you
some performance advantage which will vary depending on the underlying
cluster size of the file system, general filesystem overhead, disk
fragmentation and a host of other properties that our outside your
control as a programmer. Even coding is assembler creating a 10GB file
with each byte zeroed is going to be a slow process...


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
 
R

Robert Klemme

i can't use dd, cause i want a cross-platform application

dd runs on my Linux, cygwin, Solaris, HP UX... - pretty cross platform
I'd say. :)

The question is - do you need the whole file to be allocated or not? If
yes, a solution is slow regardless of programming language.

Cheers

robert
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top