i want to write around 50MB of data to a raw file to verify my file
system. i have done it in rough way by writing chunk of character
bytes up to 50MB in a while loop.
something like storing a string in a buffer and writing into a file
and repeating this several times.
sorry for asking silly Question, is there any good way of doing it?
-sops
--
comp.lang.c.moderated - moderation address: cl...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Check out POSIX mmap. You can map your file/device into memory and
work with the buffer directly.
Cheers,
Patrick
That's a very bad idea if the file is newly created.
DES
--
Dag-Erling Smørgrav - d...@des.no
You could buffer it up and write in big chunks (preferably an exact
multiple of the
file systems block size - say 4k, 8k or more). (Thats what fwrite()
etc does for you).
However, for small amounts of data like this, and from the users
perspective, writing it out usually will take no time at all, as the
system will not immediately write the stuff to the disk.
Modern systems use "delayed write" where they keep the data in system
buffers for as long as possible.
Then, when the write is actually done, the waiting blocks may be
sorted in disk position order before the write so that the head
movement is minimised. Also other programs may want to the read the
data and its handy if its in memory already. Finally, your program
may want to add to a partially written block.
mmap is great for reading data, (CreateFileMapping/MapViewOfFile in
windows). But you generally cannot grow a file with mmap which makes
normal output difficult. Altering an existing file OTOH is dead easy.
Jeremy