[R] [R-sig-hpc] Quickest way to make a large "empty" file on disk?

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu May 3 05:04:00 CEST 2012


On most UNIX systems this will leave a large unallocated virtual "hole" in the file. If you are not bothered by spreading the allocation task out over the program execution interval, this won't matter and will probably give the best performance.  However, if you wanted to benchmark your algorithms without the erratic filesystem updates mixed in, then you need to write all of those zeroes. For that to work most efficiently, write data in large blocks, and if possible bypass the C standard library.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Simon Urbanek <simon.urbanek at r-project.org> wrote:

>
>On May 2, 2012, at 6:23 PM, Jonathan Greenberg wrote:
>
>> R-helpers:
>> 
>> What would be the absolute fastest way to make a large "empty" file
>(e.g.
>> filled with all zeroes) on disk, given a byte size and a given number
>> number of empty values.  I know I can use writeBin, but the "object"
>in
>> this case may be far too large to store in main memory.  I'm asking
>because
>> I'm going to use this file in conjunction with mmap to do parallel
>writes
>> to this file.  Say, I want to create a blank file of 10,000 floating
>point
>> numbers.
>> 
>
>The most trivial way is to simply seek to the end and write a byte:
>
>> n=100000
>>  f=file("foo","wb")
>> seek(f,n-1)
>[1] 0
>> writeBin(raw(1),f)
>> close(f)
>> file.info("foo")$size
>[1] 1e+05
>
>Cheers,
>Simon
>
>
>> Thanks!
>> 
>> --j
>> 
>> -- 
>> Jonathan A. Greenberg, PhD
>> Assistant Professor
>> Department of Geography and Geographic Information Science
>> University of Illinois at Urbana-Champaign
>> 607 South Mathews Avenue, MC 150
>> Urbana, IL 61801
>> Phone: 415-763-5476
>> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype:
>jgrn3007
>> http://www.geog.illinois.edu/people/JonathanGreenberg.html
>> 
>> 	[[alternative HTML version deleted]]
>> 
>> _______________________________________________
>> R-sig-hpc mailing list
>> R-sig-hpc at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>> 
>>
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list