Data transfer using [userData] in function wxEvtHandler::Bind() Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Djadja
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Sep 14, 2022 5:40 pm

Data transfer using [userData] in function wxEvtHandler::Bind()

Post by Djadja »

Hi,
I am new to wxWidgets development. How much does the performance decrease in code below?
This method is needed to bind an event to an object before launching a detachable thread, which, upon completion, raises an event, but does not have a vector, since it is not needed in the thread. (accordingly I can't use getter event.GetInteger(), event.GetString() ... )

Code: Select all

...

//ID For button 
const long Frame::ID_BUTTON = wxNewId();

...

//Custom class for exchange in event
struct wxEventBuffer: public wxObject
{
    int                index;
    wxVector<wxString> vec;
};

...

//My button
m_button = new wxButton(this, ID_BUTTON, "CLICK");

...

//Bind event and put some value in wxEventBuffer
    wxEventBuffer* data = new wxEventBuffer;
    //Append number
    data->index = 1;
    //Append vector
    data->vec.push_back("One");
    data->vec.push_back("Two");
    data->vec.push_back("Three");
    //Bind event with userData
    Bind(wxEVT_BUTTON, &Frame::buttonClick, this, ID_BUTTON, wxID_ANY, data);
...

//Button event
void Frame::buttonClick(wxCommandEvent& event)
{
    //Get userData
    wxEventBuffer* data = static_cast<wxEventBuffer*>(event.GetEventUserData());
    /*
    	Do something
    	
    */
}
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Data transfer using [userData] in function wxEvtHandler::Bind()

Post by doublemax »

There is no performance impact, it's just a pointer. No data will be copied.
Use the source, Luke!
Djadja
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Sep 14, 2022 5:40 pm

Re: Data transfer using [userData] in function wxEvtHandler::Bind()

Post by Djadja »

doublemax,
Cool! Thanks for the answer!
Post Reply