C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: resizing a file

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Francis Glassborow
Guest





PostPosted: Sat Jun 28, 2003 11:30 pm    Post subject: Re: resizing a file Reply with quote



In message <bdi3c2$sf3o4$1 (AT) ID-147601 (DOT) news.dfncis.de>, Luca Pireddu
<j_unk_bucket (AT) hotmail (DOT) com> writes
Quote:
Hi all. Is it possible to resize a file?
I have two applications running that communicate via two text files (one for
input, one for output). At each step I'd like to resize the file so that
it finishes when the data ends (no extra garbage at the end). So far the
best idea I have is to close the file and open it with ios::trunc at each
step. The file would then grow to the appropriate size as I wrote data.
Any better strategies that would save me from continuously opening and
closing the file?


Why do you want to do this. In general if you open a file for writing
you either do so in append mode or you do so in truncated mode. Either
way your file would not normally be larger than necessary (but remember
that OSs allocate blocks of storage (commonly 4k at a time) for files
and that is the smallest amount that can be allocated.

--
ACCU Spring Conference 2003 April 2-5
The Conference you should not have missed
ACCU Spring Conference 2004 Late April
Francis Glassborow ACCU


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Luca Pireddu
Guest





PostPosted: Wed Jul 02, 2003 2:21 am    Post subject: Re: resizing a file Reply with quote



Francis Glassborow wrote:

Quote:
In message <bdi3c2$sf3o4$1 (AT) ID-147601 (DOT) news.dfncis.de>, Luca Pireddu
[email]j_unk_bucket (AT) hotmail (DOT) com[/email]> writes
Hi all. Is it possible to resize a file?
I have two applications running that communicate via two text files (one
for
input, one for output). At each step I'd like to resize the file so that
it finishes when the data ends (no extra garbage at the end). So far the
best idea I have is to close the file and open it with ios::trunc at each
step. The file would then grow to the appropriate size as I wrote data.
Any better strategies that would save me from continuously opening and
closing the file?


Why do you want to do this. In general if you open a file for writing
you either do so in append mode or you do so in truncated mode. Either
way your file would not normally be larger than necessary (but remember
that OSs allocate blocks of storage (commonly 4k at a time) for files
and that is the smallest amount that can be allocated.


Simply to avoid closing and opening the file at each transaction with the
outside application. It's premature optimization, I know. In any case,
from previous posts it seems that there is no portable way to do this. I
have implemented the program to open the file and truncate it at each
transaction. Thanks for your time.

--
Luca Pireddu
Mirarco - Laurentian University
Email: lpireddu@n.o.s.p.am.mirarco.org

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.