 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Francis Glassborow Guest
|
Posted: Sat Jun 28, 2003 11:30 pm Post subject: Re: resizing a file |
|
|
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
|
Posted: Wed Jul 02, 2003 2:21 am Post subject: Re: resizing a file |
|
|
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 |
|
 |
|
|
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
|
|