Is there a way to increase the 10,000 gadget limit?

Just starting out? Need help? Post your questions and find answers here.
alban
New User
New User
Posts: 5
Joined: Tue May 20, 2008 7:42 pm

Is there a way to increase the 10,000 gadget limit?

Post by alban »

Is there a way to increase the 10,000 gadget limit?

To explain: Its not that I have 10,000 actual gadgets, but I do have an application where I would like to use the gadget numbers sparsely to find the gadget that someone has clicked on. In the application I display a number of tabs with a scroll view containing a number of components. Each component is composed of 16 gadgets, I might have up to 16 components on a tab, I may have up to 32 tabs in the application.
This is working fine but it is running close to the 10,000 gadget limit.
The tabs are using 8192 potential gadget IDs without considering all the other gadgets that the application needs and without being able to expand the application very much.
In the event loop I use the gadget id number to locate the tab and the component that the user has just clicked on - this is the main reason I want to use specific numbers for the gadgets.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

hi,

where did you see this '10 000' limit ?

i don't think there's such a limit in the Gadget Lib.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post by Foz »

Is this the windows limitation you are referring to? 10,000 is the maximum number of GDI Objects that can be created and maintained by one app at any time.

I believe (and this will have to be checked) if you are not displaying them, then they don't count.
alban
New User
New User
Posts: 5
Joined: Tue May 20, 2008 7:42 pm

Post by alban »

No it is a purebasic compiler limit
The purebasic compiler displays an error message when you use a gadgetID greater than 10,000.
To see it do this:-

Code: Select all

; 
If OpenWindow(0, 0, 0, 230, 90, "Event handling example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

   If CreateGadgetList(WindowID(0))
     ButtonGadget  (10001, 10, 10, 200, 30, "Click me")
   EndIf

   Repeat
     Event = WaitWindowEvent()
   Until Event = #PB_Event_CloseWindow
 EndIf
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post by Foz »

Ah, probably enforced by the compiler because of the windows limitation.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

alban wrote:...find the gadget that someone has clicked on.
Maybe I'm still out to lunch, but how about using EventGadget() and EventType() to accomplish this task :?:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

It is the debugger which displays this message. Its actually not a hard limit.

The IDs are allocated in an array, so using them sparsely is a waste of memory.
For such things, using #PB_Any to get a dynamic ID is probably the better solution.
quidquid Latine dictum sit altum videtur
alban
New User
New User
Posts: 5
Joined: Tue May 20, 2008 7:42 pm

Post by alban »

Thanks very much everyone for your help; that makes sense Freak, I assumed that the debugger warning was a fatal message when I encountered it in a real program that I was debugging, and I did some work to pair things down to fit into that limit.
I am using GadgetEvent() Sparkie its just that at the moment I get the x,y position (in my data) and the gadget number out of the gadget id that it returns. Now I know these IDs are using an array internally - I can gain some memory back by doing things another way.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

The limit for such objects is 18.000 (per process)
http://msdn.microsoft.com/en-us/library ... S.85).aspx
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Post by graves »

freak wrote:The IDs are allocated in an array, so using them sparsely is a waste of memory.
How many, exactly?.
It isn't the same thing 4 bytes (a pointer), or 1000 bytes (a fixed length structure), by every unused gadget.

I'm using gadgets from 1000 to 9999 and I like to know if I need to change my programs to reduce memory used.

EDIT:
Is this valid for the rest of objects?... as images, menus, shortcuts...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Yes, it's valid for images and other things as well.
PureBasic objects

Introduction

The purpose of this section is to describe the behaviour, creation, and handling of objects in PureBasic. For the demonstration, we will use the Image object, but the same logic applies to all other PureBasic objects. When creating an Image object, we can do it in two ways: indexed and dynamic.

I. Indexed numbering

The static, indexed way, allows you to reference an object by a predefined numeric value. The first available index number is 0 and subsequent indexes are allocated sequentially. This means that if you use the number 0 and then the number 1000, 1001 indexes will be allocated and 999 (from 1 to 999) will be unused, which is not an efficient way to use indexed objects. If you need a more flexible method, use the dynamic way of allocating objects, as described in section II. The indexed way offers several advantages:

- Easier handling, since no variables or arrays are required.
- 'Group' processing, without the need to use an intermediate array.
- Use the object in procedures without declaring anything in global (if using a constant or a number).
- An object that is associated with an index is automatically freed when re-using that index.
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Post by graves »

Thanks, Trond

Unfortunately, I NEED static index on objects. Thus I will change my programs to reduce their index number.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Its not that much actually. Currently every gadget takes up 32bytes, so if you start at 1000, you have 32k of unused memory.
Its the same for other object types. Every entry takes the space of a small data structure.
quidquid Latine dictum sit altum videtur
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

freak wrote:Its not that much actually. Currently every gadget takes up 32bytes, so if you start at 1000, you have 32k of unused memory.
Its the same for other object types. Every entry takes the space of a small data structure.
very clear :)
so it's recommend to use Enumeration /EndEnumeration or PB_Any i mean ?
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post by Seldon »

freak wrote:The IDs are allocated in an array, so using them sparsely is a waste of memory.
What do you mean exactly ?? If I do something like this:

Code: Select all

#ID_GADGET=2000
ButtonGadget(#ID_GADGET,9,9,33,33,"Button",#PB_Button_Toggle)
Does PB create an arrary of 2000 elements although I only use one gadget ? :shock:
Post Reply