Possible bug in write strings

Just starting out? Need help? Post your questions and find answers here.
Sergey
User
User
Posts: 60
Joined: Wed Jan 12, 2022 2:41 pm

Possible bug in write strings

Post by Sergey »

Maybe I'm wrong, so correct me

Code: Select all

If OpenFile(0, "test.txt")
	FileSeek(0, Lof(0))
	Repeat
		WriteStringN(0, Str(ElapsedMilliseconds()))
		Delay(1000)	
	ForEver
; 	CloseFile(0)
Else
	MessageRequester("Error", "Can't open file!")
EndIf
If I run code in the debug mode and then kill the process the file has data
And If I run compiled executable file or run code without a debugger there are no strings in the file
Why?

And <ForEver> not hilighted in post ;-)


// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)
Last edited by Sergey on Tue Nov 19, 2024 10:11 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Possible bug in write strings

Post by mk-soft »

Programme is never terminated and the file buffer is not written.
Something like this should never be written !!!
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Possible bug in write strings

Post by BarryG »

How can you run it when you've got "FileSeek(Lof(0))" without a file number? The code doesn't even compile.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Possible bug in write strings

Post by infratec »

Code: Select all

WriteStringN(0, Str(ElapsedMilliseconds()))
FlushFileBuffers(0)
Should do the trick.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Possible bug in write strings

Post by BarryG »

Maybe even using the #PB_File_NoBuffering flag with OpenFile().
User avatar
NicTheQuick
Addict
Addict
Posts: 1527
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Possible bug in write strings

Post by NicTheQuick »

Closing the file is essential to write every buffer persistently.
Last edited by NicTheQuick on Tue Nov 19, 2024 11:04 am, edited 1 time in total.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Sergey
User
User
Posts: 60
Joined: Wed Jan 12, 2022 2:41 pm

Re: Possible bug in write strings

Post by Sergey »

infratec wrote: Tue Nov 19, 2024 7:53 am

Code: Select all

WriteStringN(0, Str(ElapsedMilliseconds()))
FlushFileBuffers(0)
Should do the trick.
Ha, it's work!

Thank you all for understanding

BarryG this is a test code of LOG file in case the system turns off unexpected
Yes, I need #PB_File_NoBuffering, cool!
Each time will learn something new in PureBasic
Last edited by Sergey on Tue Nov 19, 2024 2:07 pm, edited 6 times in total.
Olli
Addict
Addict
Posts: 1266
Joined: Wed May 27, 2020 12:26 pm

Re: Possible bug in write strings

Post by Olli »

infratec wrote: Tue Nov 19, 2024 7:53 am

Code: Select all

WriteStringN(0, Str(ElapsedMilliseconds()))
FlushFileBuffers(0)
Should do the trick.
Thank you infratec. My suggest would have pushed on the shared i/o option in the OpenFile() arguments.

I note that the BarryG suggest seems to be safer, in the shut down ways.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Possible bug in write strings

Post by infratec »

For logging I always open with the flag #PB_File_Append (no FileSeek() needed) and close the file for each log entry.
Because then I can use tail :wink:
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Possible bug in write strings

Post by idle »

What's faster in a multi writer senario
Keeping a file open appending and flush or open append close?
Sergey
User
User
Posts: 60
Joined: Wed Jan 12, 2022 2:41 pm

Re: Possible bug in write strings

Post by Sergey »

idle wrote: Tue Nov 19, 2024 6:26 pm What's faster in a multi writer senario
Keeping a file open appending and flush or open append close?
It all depends on the situation, in my case, the recording is made with many strings, so I chose a flush method
If there aren't so many strings, it's better to use closefile :wink:
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Possible bug in write strings

Post by idle »

Sergey wrote: Tue Nov 19, 2024 11:29 pm
idle wrote: Tue Nov 19, 2024 6:26 pm What's faster in a multi writer senario
Keeping a file open appending and flush or open append close?
It all depends on the situation, in my case, the recording is made with many strings, so I chose a flush method
If there aren't so many strings, it's better to use closefile :wink:
I'm interested in the latencies between the methods, especially from multiple threads, though it won't be hard to test but I haven't gotten to the stage where I'm focusing on writing to disk.
Olli
Addict
Addict
Posts: 1266
Joined: Wed May 27, 2020 12:26 pm

Re: Possible bug in write strings

Post by Olli »

The worst thing, I have got on this theme of mass memory recording, is a total copy of all my file I wanted to copy to an USB key, with all my datas zeroed, after having unplugged, and then unplugged.
Post Reply