Creating a file with $SIZE

Bryan Olson fakeaddress at
Fri Mar 14 10:12:29 CET 2008

Robert Bossy wrote:
> cokofreedom at wrote:
>> Robert Bossy wrote:  
>>> Indeed! Maybe the best choice for chunksize would be the file's buffer
>>> size... 

That bit strikes me as silly.

>>> I won't search the doc how to get the file's buffer size because
>>> I'm too cool to use that function and prefer the seek() option since
>>> it's lighning fast regardless the size of the file and it takes near to
>>> zero memory.
>> But what platforms does it work on / not work on?
> Posix. 

Posix is on the does-work side, just to be clear.

> It's been ages since I touched Windows, so I don't know if XP and 
> Vista are posix or not.

I tried on WinXP, with both an NTFS and FAT32 disk, and it worked
on both.

I found some Microsoft documentation noting: "On some
platforms, seeking past the end of a file and then doing a write
operation results in undefined behavior."

> Though, as Marco Mariani mentioned, this may create a fragmented file. 
> It may or may not be an hindrance depending on what you want to do with 
> it, but the circumstances in which this is a problem are quite rare.

Writing zeros might also create a fragmented and/or compressed file.
Using random data, which is contrary to the stated requirement but
usually better for stated application, will prevent compression but
not prevent fragmentation.

I'm not entirely clear on what the OP is doing. If he's testing
network throughput just by creating this file on a remote server,
the seek-way-past-end-then-write trick won't serve his purpose.
Even if the filesystem has to write all the zeros, the protocols
don't actually send those zeros.


More information about the Python-list mailing list