Gadget Object number high error message

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Gadget Object number high error message

Post by IdeasVacuum »

Tiny issue.

If you have a Gadget number that is deemed to be high, the compiler halts with an error message:
Error #Gadget object number is very high (over 10000) are You sure of that?
Certainly will be times when the developers answer to that question is 'yes'.

It would be much better to report (a) the actual gadget number and (b) the maximum number allowed.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Gadget Object number high error message

Post by Trond »

Certainly will be times when the developers answer to that question is 'yes'.
Why would anyone want to create 10000 gadgets?
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: Gadget Object number high error message

Post by ozzie »

I recollect getting a similar problem when using the debugger - except it was a warning, not an error - when the gadget number I was using had been 'generated' by #PB_Any. I changed my code to use my own gadget numbers.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Gadget Object number high error message

Post by IdeasVacuum »

Why would anyone want to create 10000 gadgets?
No doubt somebody will, but it's not about the actual quantity of gadgets, its about using 'smart' Gadget ID systems where inter-related gadgets are recorded as such by their ID being a member of a number group.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Gadget Object number high error message

Post by Shield »

Hey! :)

I'd recommend using the #PB_Any feature.
You can group your gadget "numbers" in Linked Lists or arrays or some other data structures,
which are perfectly if you need to iterate through them and when you are
going to create them dynamically. :)

First I always used "hardcoded" Gadget IDs and it worked OK, but at some point
when you get a lot of other Gadgets and Windows, it's just going to be confusing
and I also got that error because I tried to do it in a smart way.

IdeasVacuum wrote:
Why would anyone want to create 10000 gadgets?
No doubt somebody will [...]
Hehe, 10k Gadgets would be quite the overkill. :mrgreen:
IIRC, there is a window / control limit set by Windows (and probably other operating systems, too).
I don't think you're actually allowed to create that many controls.


Greetings
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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Gadget Object number high error message

Post by Trond »

IdeasVacuum wrote:
Why would anyone want to create 10000 gadgets?
No doubt somebody will, but it's not about the actual quantity of gadgets, its about using 'smart' Gadget ID systems where inter-related gadgets are recorded as such by their ID being a member of a number group.
Don't do that. All the unused numbers in-between are still allocated, so you're wasting a ton of memory.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Gadget Object number high error message

Post by IdeasVacuum »

Don't do that. All the unused numbers in-between are still allocated, so you're wasting a ton of memory.
That seems strange, why are unspecified IDs allocated?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Gadget Object number high error message

Post by Shield »

Because apparently PureBasic creates an array to hold all Gadget numbers,
no matter if they are actually used or not.
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
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Gadget Object number high error message

Post by skywalk »

http://www.purebasic.com/documentation/reference/handles.html wrote: Handles and Numbers
Also, most of the functions that create these objects also return this handle as a result, if they were successful. This is only the case if #PB_Any was not used to create the object. If #PB_Any is used, these commands return the object number that was assigned by PB for them, not the handle.
I use #PB_Any almost always, but don't understand the difference between object numbers assigned automatically vs those assigned by a user constant?

Why is more memory consumed when a user assigns an arbitrary constant of 10000 for a gadget?
Yet, the #PB_Any object number is just as high?
Couldn't the compiler just sort and reassign constants to eliminate gaps?
I assume the use of #PB_Any is not wasting memory.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Gadget Object number high error message

Post by Trond »

The #PB_Any numbers are direct pointers to memory. While the normal numbers are indexes in an array.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Gadget Object number high error message

Post by PMV »

Documented in PB-Helpfile
In Overview under "Various Topics" click on "PureBasic objects overview"

MFG PMV
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Gadget Object number high error message

Post by Shield »

skywalk wrote: I use #PB_Any almost always, but don't understand the difference between object numbers assigned automatically vs those assigned by a user constant?
As Trond pointed out correctly, #PB_Any values are actually pointers that store the necessary information about the gadgets, the OS handle for example.
skywalk wrote: Why is more memory consumed when a user assigns an arbitrary constant of 10000 for a gadget?
I just said that one post above yours. PB allocates an array with (at least) the size of the largest gadget number.
If you're creating a gadget with the ID 10'000, PB creates an array with the size of 10'000 fields and stores the information about
that gadget at position 10'000 in order to directly access them. All the other elements are empty until you create gadgets with those numbers.
(If that's not what PB does, please tell me).
skywalk wrote: Yet, the #PB_Any object number is just as high?
Couldn't the compiler just sort and reassign constants to eliminate gaps?
Sure the gadget list could be optimized for size but that would prevent PB from directly accessing the information
via the array index and thus slow down the process of acquiring that information since the correct number has to be searched.
Although I think that would be a more efficient way...but then again you could just use #PB_Any which is way more flexible anyway.
skywalk wrote: I assume the use of #PB_Any is not wasting memory.
Nope. If you use #PB_Any, PB can access the information directly since it is a pointer. :D
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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Gadget Object number high error message

Post by IdeasVacuum »

There are times I think when PB_Any is going to complicate matters too much in the code. So, my approach will now ensure my code is 'ID array aware' and reduce logical numbering. Not a huge sacrifice, just that I like to keep my code minimal and as easy as possible for me to understand if I have to go back to it months or years later :lol:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Gadget Object number high error message

Post by skywalk »

Thanks Shield, I saw your earlier post after mine.

@IdeasVacuum, I actually find the enumerated gadgets harder to deal with, unless it is a very small app/utility. Otherwise, I have a structured array of all my windows/gadgets/menus/etc. and the properties I automate.
With AutoComplete and the '\' key, the properties jump right out so there's not much to remember. :wink:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply