Page 1 of 2
Closing Time
Posted: Sun Jan 08, 2012 5:57 pm
by GWS
Hi,
Here's a simple skeleton window program. (I'm trying out Microsoft window style codes rather than the rather verbose PB constants).
Code: Select all
Define.l win,run
; some window style flags in Microsoft magic number format ..
; System Menu only $c80000
; Minimize $ca0000
; Maximize $c90000
; Sizeable $c40000
; Centred on screen 1
; Centred in Parent Window 2
; System, Min, Max $cb0000
; System, Min, Max and Sizeable $cf0000
OpenWindow(win, 0, 0, 300, 200, "Window Skeleton ", $c80001)
SetWindowColor(win, RGB(50,120,180))
ButtonGadget(1,120,140,60,25,"Exit")
run = 1
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
run = 0
Case #PB_Event_Gadget
Select EventGadget()
Case 1
run = 0
EndSelect
EndSelect
Until run = 0
End
Question is, would the END statement handle closing any active timers, sounds and images - or should they be closed explicitly in a shutdown routine ?
best wishes,
Graham
Re: Closing Time
Posted: Sun Jan 08, 2012 6:05 pm
by Shield
The end statement doesn't do anything really.
When a program ends, the operating system takes care of releasing any resources, so you don't need
to worry about memory leaks or something like that. However, there are some native WinAPI functions that need to be handled carfully.
But as long as you're using PB only functions or the vast majority of WinAPI functions, you won't run into any problems.
It's still good practice though to clean everything up yourself.
That way you can also keep track of memory leaks or other unwanted behaviour during runtime,
for example if you allocate more memory than you free at the end.

Re: Closing Time
Posted: Sun Jan 08, 2012 6:13 pm
by GWS
It's still good practice though to clean everything up yourself.
Thanks Shield .. I'll do that then.
all the best,
Graham
Re: Closing Time
Posted: Sun Jan 08, 2012 6:27 pm
by ts-soft
At the end of Program, the most is freed by windows (for example Memory) and the rest by PB, for example PB closes all opened
Files. But this doesn't require the "End" command, only the end of program.
Re: Closing Time
Posted: Mon Jan 09, 2012 3:56 am
by Demivec
The use of
End in a program is not required but is included in the keywords as a matter of completeness with other BASIC keywords.
A handy use of
End is to use it in conjunction with
EnableExplicit at the top of your source. Place
End first, then
EnableExplicit. Then compile your code. It will check the source for declared variables and procedures but won't run any of it. Don't forget to remove
End after your done checking the variable and procedure names.

Re: Closing Time
Posted: Mon Jan 09, 2012 4:21 am
by skywalk
Demivec wrote:Place End first, then EnableExplicit. Then compile your code. It will check the source for declared variables and procedures but won't run any of it.
Now how did you come up with that one
Nice tip Demivec.

Re: Closing Time
Posted: Mon Jan 09, 2012 9:17 am
by Demivec
skywalk wrote:Demivec wrote:Place End first, then EnableExplicit. Then compile your code. It will check the source for declared variables and procedures but won't run any of it.
Now how did you come up with that one
Nice tip Demivec.

I didn't invent it but unfortunately can't determine who suggested it first in the forum.
Re: Closing Time
Posted: Mon Jan 09, 2012 1:58 pm
by Fred
Shield wrote:The end statement doesn't do anything really.
When a program ends, the operating system takes care of releasing any resources, so you don't need
to worry about memory leaks or something like that. However, there are some native WinAPI functions that need to be handled carfully.
But as long as you're using PB only functions or the vast majority of WinAPI functions, you won't run into any problems.
It's still good practice though to clean everything up yourself.
That way you can also keep track of memory leaks or other unwanted behaviour during runtime,
for example if you allocate more memory than you free at the end.

Actually PB takes care of all that, and a lot of stuff is done on end, so you can forget about manual cleanup.
Re: Closing Time
Posted: Mon Jan 09, 2012 3:00 pm
by Shield
Yeah, I'm sure PB does clean up properly as it should, but it probably doesn't make any difference
if you use End or ExitProcess_()...or does it?
Re: Closing Time
Posted: Fri Jan 13, 2012 8:48 pm
by utopiomania
Wellcome to the party, GWS, its nice to see that you are here too.
I'll do my best to help you, and so will everyone else over here.

Re: Closing Time
Posted: Fri Feb 22, 2013 7:52 pm
by WilliamL
Hey, another old, new, old programmer. (reference to another thread where it was saying everyone was old on the forum) Interesting that you want to work in Hex.
Welcome to the party. The joy of discovery every day.. at least it is for me.

Re: Closing Time
Posted: Fri Feb 22, 2013 9:20 pm
by Fred
Shield wrote:Yeah, I'm sure PB does clean up properly as it should, but it probably doesn't make any difference
if you use End or ExitProcess_()...or does it?
I didn't seen this answer, but you should really use 'End' as ExitProcess_() will exits immediately without calling PB cleanup routines.
Re: Closing Time
Posted: Fri Feb 22, 2013 9:34 pm
by PMV
Demivec wrote:Place End first, then EnableExplicit. Then compile your code. It will check the source for declared variables and procedures but won't run any of it.
As i remember the changelog, PB5.10 comes with the possibility
to just compile everything without running the created program.
So you don't have to write that "end"
The "end" Command is usefull because you can stop execution
whereever it is needed.

Re: Closing Time
Posted: Fri Feb 22, 2013 9:40 pm
by Demivec
PMV wrote:Demivec wrote:Place End first, then EnableExplicit. Then compile your code. It will check the source for declared variables and procedures but won't run any of it.
As i remember the changelog, PB5.10 comes with the possibility
to just compile everything without running the created program.
So you don't have to write that "end"
The "end" Command is usefull because you can stop execution
whereever it is needed.

Yes, it's a nice addition to v5.10, however last year (when the suggestion was made) that wasn't possible.

Re: Closing Time
Posted: Sat Feb 23, 2013 9:31 am
by davido
Reassuring to know that Fred has arranged for end to clear up any mess-up my code might make!
