wxTimers and ids

View: New views
1 Messages — Rating Filter:   Alert me  

wxTimers and ids

by Tamer El Nashar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

wx: cvs
os: win xp pro sp3
compiler: vc7

Hello,

We ran into a few issues to do with wxTimer and their ids. We have a set of custom controls, that are reused throughout our different applications, these controls are basically classes, that of course can have many instances of them instantiated at one time. One of our custom controls, wxCustomBitmapButton has 2 wxTimer* members. We can have more than  50 wxCustomBitmapButtons in one application, which would mean we can have 100 timers created in our application at one time (though only one timer can be running at once). Also 100 timers does not include other custom controls that also have wxTimer members, as well as other wxTimer members used throughout our app.
After a recent update to wx, we started getting "timer creation failed" messages randomly, while our application was running. Initially we thought it was the fact that we thought we had too many timers in our application (as we read in the wx docs that timers were a limited resource under windows). So we changed our wxTimer members in our custom controls to static members, and used reference counting to create and delete the timers. That didn't solve the problem.
After some searching, we figured it was the fact that we were creating several timers, with the same id, while each wxTimer was supposed to have a unique id. We were using enums for ids, and we changed it to use wxID_ANY, to ensure they were unique ids, and that fixed the problem.
Now 2 questions regarding the scenario mentioned above:
  1. Should changing our wxTimer members to static members (i.e. less timers created) have an affect on performance?
  2. How limited are  wxTimers under window? (i.e max of 1000 timers)
  3. How can have global unique ids to be used in our custom controls, that would never conflict with our app ids?
    1. Should we use wxNewId() as it is still used in one of the samples (event sample) with the most recent wx.
    2. Or should we keep our current code:
all in wxCustomBitmapButton.cpp:
                   // Define our ids
                   int ID_TIMER = wxID_ANY;
                   int ID_ONESHOT_TIMER = wxID_ANY;
                  
                   // Handle our events using an event table
                   EVT_TIMER(ID_ONESHOT_TIMER, wxCustomBitmapButton::OnOneShotTimer)
                   EVT_TIMER(ID_TIMER, wxCustomBitmapButton::OnTimer)

                   // Create our timers in the constructor
                   if (m_TimerRef == 0)
                   {
                            m_Timer = new wxTimer(this, ID_TIMER);
                            m_OneShotTimer = new wxTimer(this, ID_ONESHOT_TIMER);
                   }

                   // Redefine our ids
                   ID_TIMER = m_Timer->GetId();
                   ID_ONESHOT_TIMER = m_OneShotTimer->GetId();

Thanks in advance for any help.

Tamer El Nashar
VRSonic, Inc.
   

--~--~---------~--~----~------------~-------~--~----~
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+unsubscribe@...
or visit http://groups.google.com/group/wx-users
-~----------~----~----~----~------~----~------~--~---