[Insight-developers] Portability of seeking past the end of a file

Bradley Lowekamp blowekamp at mail.nih.gov
Tue Jan 27 10:15:29 EST 2009


Hello,

	I just learned something (perhaps I used to know it but it was never  
useful before), and I am wondering if anyone has knowledge of  
portability issues. It's demonstrated in the following code:

std::ofstream fp(fname, std::ios_base::binary | std::ios_base::out |  
std::ios_base::trunc);
fp.seekp(1024*1024*1024);
std:: cout << fp.tellp() << std::endl;
fp.put(char(0));


	Basically we create a file and truncate it, then seek to the 1GB mark  
and write, there by creating a 1GB file. What is really cool it what  
the OS and file systems do. They create files with whole in them, that  
is they don't actually store/write the whole file they just make the  
filesystem structure needed for it. I have tested this with NTFS, OSX  
extended, and linux file systems. I wouldn't be surprised if fat 32  
has to write out the whole file though.
	This should be good for solving my problems with the pasting meta io  
files.

Any comments on the portability of this approach?

Brad

========================================================
Bradley Lowekamp
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20090127/0b6b8a13/attachment.htm>


More information about the Insight-developers mailing list