How do I create a main loop for Multiple-Forms?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

good point...
maybe the information is outdated.

I based my sentence "enumerating with other start-numbers or with gaps will
cause no Error but may lower Performance. " on this information....
oh... and have a nice day.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

OK, you're right - I didn't actually open Window Two in my first test. It uses the memory dynamically, so I saw a noticeable increase (around 300k) with Enumeration 4990 compared to #PB_Compiler_EnumerationValue when I actually opened the window.
BERESHEIT
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Ok, now I'm lost. Can someone put that into perspective, and show
an example of good vrs bad?

- np
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

It's not a huge deal. Basically, it's just an issue of how much memory you're setting aside for gadgets by your choice of gadget numbers. For readability, I numbered my objects 0-99 for the main window, 100-199 for Window 1 and 200+ for Window 2. In doing so, when I open Window 2, enough memory gets set aside to store data for 200 gadgets because I left gaps in the numbers. We're not talking about a lot of memory here, just a couple of k. Using Enumeration #PB_Compiler_EnumerationValue to start your Enumeration blocks allows you to start a new enumeration for code readablility without creating gaps in the enumerations. For example:

Code: Select all

Enumeration  ; starts at 0
  #This      ; 0
  #That      ; 1
  #TheOther  ; 2
EndEnumeration

Enumeration #PB_Compiler_EnumerationValue ; picks up where the last block left off
  #MoreThis  ; 3
  #MoreThat  ; 4
EndEnumeration 

Enumeration 100 ; starts at 100, leaving a large gap in the numbers used for objects/gadgets
  #MoreYet      ; 100
  #MoreStill    ; 101
Endenumeration
Personally, I think the few extra k of memory used by the program at runtime is worth the extra readability / debuggability of being able to look at a gadget number and instantly know where it belongs. But that's a personal preference, for someone else the idea of creating a program that uses the smallest memory footprint possible is more attractive. Both viewpoints are valid and have strong/weak points. But in the end we're only talking about a memory allocation far less than one megabyte in size, so it's not a dealbreaker either way.
BERESHEIT
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

ts-soft wrote:@netmaestro

Code: Select all

Enumeration ;Window One
  #wOne
  #wOne_Txt_Text1
  #wOne_Btn_Button1
EndEnumeration

Enumeration #PB_Compiler_EnumerationValue ; Window Two
  #wTwo
  #wTwo_Txt_Text1
  #wTwo_Btn_Button1
EndEnumeration
thats a bit long winded.

Better like this:

Code: Select all

Enumeration
  ;window1
  #wOne
  #wOne_Txt_Text1
  #wOne_Btn_Button1
  ;window2
  #wTwo
  #wTwo_Txt_Text1
  #wTwo_Btn_Button1
EndEnumeration
--Kale

Image
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You're quite right, Kale, the #PB_Compiler_EnumerationValue is generally more usefull in code-generation scenarios, I often use the comments myself.
BERESHEIT
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Event Managing w/main loop and Multiple Window forms

Post by Tenaja »

I know this is an old thread, but I was looking for a "best practice" technique for this, and the post came in handy. I could think of a few ways to do it, but after seeing the samples here, I have made up my mind. Special thanks to you, netmaestro, for a great sample that will scale up well. (My "main loop" was already 8 pages long, and adding windows was getting it crazy!)
Post Reply