Closing Time

Just starting out? Need help? Post your questions and find answers here.
User avatar
GWS
User
User
Posts: 23
Joined: Tue Sep 27, 2005 9:51 pm
Location: Staffs. UK

Closing Time

Post 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
Tomorrow may be too late ..
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Closing Time

Post 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. :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
GWS
User
User
Posts: 23
Joined: Tue Sep 27, 2005 9:51 pm
Location: Staffs. UK

Re: Closing Time

Post by GWS »

It's still good practice though to clean everything up yourself.
Thanks Shield .. I'll do that then.

all the best, :)

Graham
Tomorrow may be too late ..
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Closing Time

Post 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.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Closing Time

Post 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. :wink:
User avatar
skywalk
Addict
Addict
Posts: 4223
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Closing Time

Post 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 :shock:
Nice tip Demivec. 8)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Closing Time

Post 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 :shock:
Nice tip Demivec. 8)
I didn't invent it but unfortunately can't determine who suggested it first in the forum.
Fred
Administrator
Administrator
Posts: 18254
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Closing Time

Post 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.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Closing Time

Post 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?
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: Closing Time

Post 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. :)
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Closing Time

Post 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. :)
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
Fred
Administrator
Administrator
Posts: 18254
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Closing Time

Post 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.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Closing Time

Post 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. :wink:
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Closing Time

Post 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. :wink:
Yes, it's a nice addition to v5.10, however last year (when the suggestion was made) that wasn't possible. :wink:
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Closing Time

Post by davido »

Reassuring to know that Fred has arranged for end to clear up any mess-up my code might make! :D
DE AA EB
Post Reply