Hehe... Doesn't work - the Crapsfiles stops generating at "CrapFile433464.txt". Windows limitation? Can you only have 433464 files in a directory?!?!GeoTrail wrote:thefool wrote:Ha! I winI win heheheCode: Select all
For i=0 To 1000000 CreateFile(0, "C:\Crap\CrapFile"+Str( i )+".txt") WriteStringN(0, "This is just a crap file...") WriteStringN(0, "This is just a crap file...") WriteStringN(0, "This is just a crap file...") WriteStringN(0, "This is just a crap file...") WriteStringN(0, "This is just a crap file...") WriteStringN(0, "This is just a crap file...") WriteStringN(0, "This is just a crap file...") CloseFile(0) Next i
Another GetDirectorySize() Procedure (PB4.01)
-
- Addict
- Posts: 1126
- Joined: Wed Oct 15, 2003 12:40 am
- Location: Sweden
- Contact:
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
-
- Addict
- Posts: 1126
- Joined: Wed Oct 15, 2003 12:40 am
- Location: Sweden
- Contact:
Pretty much yeah!AND51 wrote:Thank you! Very interesting!
So if I createa threaad, the thread can start faster, if I've got a Delay(0) in my main module? And if there is no thread is to be started, my main module wouldn't be influcened, because Delay(0) immediately returns...
But even if you do not use multiple threads, it is still advised to do it in loops you know are "heavy" (use a lot of cpu, or takes a while to complete)
The machine will seem to work smoother. (users will be able to browse the net or watch a movie while they wait for the program to complete whatever it's doing)
Best of all, using Delay(0) in loops (while/for/foreach and similar) while developing a program is smart too,
if the loop is buggy you will still be able to bring up Task Manager or Kill it from the IDE.
So I recommend using Delay(0) in any application at the least,
preferably Delay(1) in the main window loop,
for "paused" programs I tend to use Delay(1000) (actualy WaitWindowEvent(1000) is what I use then instead)
I would not recommend using more than Delay(20) in a GUI loop if you use WindowEvent(), longer delays than 20ms makes the GUI very "sluggish".
Anyway, I'm getting totally off topic from the original posts here, sorry.
Maybe WaitWindowEvent(1000) and Delay(0) and Delay(1) should be added to the PB manual's Window and loop sections as "tips",
or add it to the FAQ or somewhere. veterans are aware of this (I hope) as it's considered good coding/multitask friendly coding and will benefit single cpu's as well as multi-cpu systems.
Beginner coders are not always aware of easy performance "tricks" like this. Remember, a program runs under a operating system so you must not consider only the performance of your program, but how your program affect the performance of the OS while running as well.
(PS! if anyone want to, feel free to "steal" my blabber above/rewrite it and post it as a Tips'n'tricks post or similar.)
@ Resactor: Thank you very much for your information!!!
Can I also use WaitWindowEvent(0) insted of Delay(0)? Then I don't have to write so much.
Your knowlege is very useful. If you want, you can give me/us more of these information.
Can I also use WaitWindowEvent(0) insted of Delay(0)? Then I don't have to write so much.
Your knowlege is very useful. If you want, you can give me/us more of these information.
PB 4.30
Code: Select all
onErrorGoto(?Fred)
Yes! It seems that WaitWindowEvent(0) works. However for a normal application I'd advise WaitWindowEvent() or WaitWindowEvent(1000) for example, and for apps that need to update it's display regulary use WaitWindowEvent(1) or WaitWindowEvent(20) depending on your needs,AND51 wrote:Can I also use WaitWindowEvent(0) insted of Delay(0)? Then I don't have to write so much.
as WaitWindowEvent(0) uses all free cpu. (but does not lock up the system luckily
Thanks to WaitWindowEvent() supporting a delay, I find WindowEvent() almost obsolete. (but just almost, as some games may need a custom delay loop for example by using WindowEvent() and Delay() in it's main loop)
Bah, right now I wish I was a mod so I could split these delay posts out of this thread and into general instead. This topic is like two different things now. *beats himself up*
-
- Enthusiast
- Posts: 468
- Joined: Sat Dec 20, 2003 6:19 pm
- Location: Switzerland
WindowEvent() ist not depreciated, as you sometimes need to empty the message queue in loops, for example:
Not emptying the message queue leads to a not reacting GUI, which is about to be destroyed and then it won't be redrawn.
Code: Select all
Foreach myList()
While WindowEvent() : Wend
; CODE
next
PB 4.30
Code: Select all
onErrorGoto(?Fred)
Sure there is.remi_meier wrote:Sorry, I can't see any use for WaitWindowEvent(1000)? :roll:
WaitWindowEvent(1000) would return whenever there is a window event. But by specifying 1000 you would be guaranteed it would return aprox. once per second.
So you could use ElapsedMilliseconds() to meassure time passed, allowing you do to "automatic updates" checking in a very system friendly way.
WaitWindowEvent(1000) would also be usefull for a clock or anything else that need to be updated at least once per second.
Obviously you could use WaitWindowEvent(1000*3600) which is 1 hour or even WaitWindowEvent(1000*86400) which is 24 hours.
WaitWindowEvent() would still return instantly if any window events happen. (user clicking a button, system message etc)
Think of it as a forced event 0.
*looks at the post above* Can't see I ever mentioned those two together at all. And no I do not recommend using WaitWindowEvent() and Delay() together.remi_meier wrote:And there is really no reason to use a Delay() with WaitWindowEvent().
I said "I find WindowEvent() almost obsolete", as I do still use it in a few special cases, and I never said deprecated.AND51 wrote:WindowEvent() ist not depreciated
I'd rather prefer people quoted me exactly (with all the flaws, if any), rather than paraphrasing or reading something that was never written, thus totally changing the meaning of what I said.
I meant, that it is even not almost depreciated/obsolete.
Question:
I showed you how I empty the message queue in heavy loops: While WindowEvent() : Wend
Can I also use While WaitWindowEvent(0) : Wend to have your Delay(0) effect in my loop? Then I don't have to write While WindowEvent() : Delay(0) : Wend.
Question:
I showed you how I empty the message queue in heavy loops: While WindowEvent() : Wend
Can I also use While WaitWindowEvent(0) : Wend to have your Delay(0) effect in my loop? Then I don't have to write While WindowEvent() : Delay(0) : Wend.
PB 4.30
Code: Select all
onErrorGoto(?Fred)
-
- Enthusiast
- Posts: 468
- Joined: Sat Dec 20, 2003 6:19 pm
- Location: Switzerland
Actually, this passage could lead to misunderstandings:>> And there is really no reason to use a Delay() with WaitWindowEvent().
*looks at the post above* Can't see I ever mentioned those two together at all. And no I do not recommend using WaitWindowEvent() and Delay() together.
For WaitWindowEvent(1000):Rescator wrote:So I recommend using Delay(0) in any application at the least,
preferably Delay(1) in the main window loop,
for "paused" programs I tend to use Delay(1000) (actualy WaitWindowEvent(1000) is what I use then instead)
I would not recommend using more than Delay(20) in a GUI loop if you use WindowEvent(), longer delays than 20ms makes the GUI very "sluggish".
Actually, I personally would use a timer/callback or a thread for something
that should be repeated in a specified period of time. But yes, this could
be an option. Just, that you cannot be sure, that the timeout is accurate
and therefore there could be some problems in updating a clock:
Code: Select all
Repeat
if elapsedmilliseconds() - time > 1000
time + 1000
UpdateClock()
EndIf
Until WaitWindowEvent(1000)
WindowEvent() could wait for another second, while the real second is
over since 0.8s? It could look a bit weird, and really weird if you use
higher timeouts, like you said 1 hour. You couldn't get around a callback/
thread/timer.
But for simple tasks, it could work. Although I will never use a timeout
of more than 500ms personally.
Code: Select all
Think of it as a forced event 0.
Athlon64 3700+, 1024MB Ram, Radeon X1600
That should work yes, but this is PureBasic, it only takes a few seconds to try new things out, so try itAND51 wrote:Can I also use While WaitWindowEvent(0) : Wend to have your Delay(0) effect in my loop? Then I don't have to write While WindowEvent() : Delay(0) : Wend.
Good point, yeah for high timeouts or accuracy one should use proper timing.remi_meier wrote:For WaitWindowEvent(1000):
Actually, I personally would use a timer/callback or a thread for something
that should be repeated in a specified period of time. But yes, this could
be an option. Just, that you cannot be sure, that the timeout is accurate
and therefore there could be some problems in updating a clock:what if there was a user event and the second isn't over then, so Wait-Code: Select all
Repeat if elapsedmilliseconds() - time > 1000 time + 1000 UpdateClock() EndIf Until WaitWindowEvent(1000)
WindowEvent() could wait for another second, while the real second is
over since 0.8s? It could look a bit weird, and really weird if you use
higher timeouts, like you said 1 hour. You couldn't get around a callback/
thread/timer.
But WaitWindowEvent(1) and similar is a excellent "cheap" loop, cheap as in easy to do and hardly any code needed. (I'm sure Fred made some pretty tight code for that feature)
And you know the coolest part of it all? (something I did not notice/think about until a few weeks ago)
time.l=1
WaitWindowEvent(time)
Using a variable, you can change the variable and WaitWindowEvent() will use the new value on it's next wait.
Obviously you can do the same with Delay(time) too,
it's just something that is easy to forget you can do. (most people just slap in a 1 *laughs*)
Ah man, I think we managed to totally ruin this thread, people searching the forums are gonna be scratching their heads when this thread pops up.