Is there error checking with file writing functions?
Is there error checking with file writing functions?
For the following functions:
WriteByte
WriteCharacter
WriteData
.
.
.
WriteStringN
WriteWord
Is there any way of checking whether the write was successful? I'm using a demo version of PureBasic.
WriteByte
WriteCharacter
WriteData
.
.
.
WriteStringN
WriteWord
Is there any way of checking whether the write was successful? I'm using a demo version of PureBasic.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
It doesn't seem to work. I set up a small test program and supposedly it wrote a 6 meg file to a floppy without complaining.netmaestro wrote:Those commands are returning 1 when successful, so a reasonable assumption would be they'd return 0 if not. But the doc doesn't say so and I don't know how you'd test it.

- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
ok.
so, the write-command does not report an error, because non happenes,
because the writing to the Buffer indeed was successful.
only forcing the buffer to write to the media will finally report the error.
not the writing-command itself, but the processing of the buffer is physical writing nowadays...
so, the write-command does not report an error, because non happenes,
because the writing to the Buffer indeed was successful.
only forcing the buffer to write to the media will finally report the error.
not the writing-command itself, but the processing of the buffer is physical writing nowadays...

oh... and have a nice day.
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
I suggest you report it as a bug,
if it is a PB bug or a issue that the PB team can fix/handle they will,
If not then maybe a note in the documentation is needed.
And when I mean a "issue" the PB team can fix,
like mean possibly checking/keeping track of free disk space per file(/drive?) updating the value each time the buffer is flushed and reduce the "space free" value each time something is written to the buffer.
I'm not sure how PB's filebuffer is implemented but a solution like that might help catch an issue like this a bit earlier than currently for example.
It is still not possible to truly eliminate this issue though, due to the nature of filebuffering. If this is a common issue with your program(s) I suggest disabling buffering for the files you write and either use your own filebuffering or do not use filebuffering at all. (writes and reads will be a lot slower though)
Using a smaller filebuffer value might also work, but again the speed issue.
Another issue with fixing this is that if multiple files are written at the same time the free space values may get out of sync between buffer flushing.
Again I got no idea how filebuffers are implemented in PB so this may or may not be easy to "fix".
PS! Normally you should always know more or less how much data you need to write to disk, so keeping track of values yourself should be not that hard.
It is also adviced that you set the filebuffer size to match the data blocks you write.
So if you write 16KB each time you write data then a filebuffer of 16KB might be best, then do a flushbuffer right after.
(actually in this case, disabling filebuffer for that file and writing the data directly might be best, filebuffers work best when you do not always know how muc data is read or written each time or when you know a lot of small reads or writes will happen. especially ReadByte and WriteByte and similar benefit a lot from some form of filebuffer.)
if it is a PB bug or a issue that the PB team can fix/handle they will,
If not then maybe a note in the documentation is needed.
And when I mean a "issue" the PB team can fix,
like mean possibly checking/keeping track of free disk space per file(/drive?) updating the value each time the buffer is flushed and reduce the "space free" value each time something is written to the buffer.
I'm not sure how PB's filebuffer is implemented but a solution like that might help catch an issue like this a bit earlier than currently for example.
It is still not possible to truly eliminate this issue though, due to the nature of filebuffering. If this is a common issue with your program(s) I suggest disabling buffering for the files you write and either use your own filebuffering or do not use filebuffering at all. (writes and reads will be a lot slower though)
Using a smaller filebuffer value might also work, but again the speed issue.
Another issue with fixing this is that if multiple files are written at the same time the free space values may get out of sync between buffer flushing.
Again I got no idea how filebuffers are implemented in PB so this may or may not be easy to "fix".
PS! Normally you should always know more or less how much data you need to write to disk, so keeping track of values yourself should be not that hard.
It is also adviced that you set the filebuffer size to match the data blocks you write.
So if you write 16KB each time you write data then a filebuffer of 16KB might be best, then do a flushbuffer right after.
(actually in this case, disabling filebuffer for that file and writing the data directly might be best, filebuffers work best when you do not always know how muc data is read or written each time or when you know a lot of small reads or writes will happen. especially ReadByte and WriteByte and similar benefit a lot from some form of filebuffer.)
Re: Is there error checking with file writing functions?
> Is there any way of checking whether the write was successful?
http://www.purebasic.fr/english/viewtopic.php?t=11902
http://www.purebasic.fr/english/viewtopic.php?t=11902
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.