In my application I want to fire an event every ~10ms using an eventbus. I am using GreenRobot Eventbus and my code looks like follows:
while (true){
//receiving data etc.
//...
eventBus.post(new DataEvent(bytes));
}
This works fine, but I am a little bit doubtful if this is efficienct, since in this code every ~10ms a new DataEvent
Object is created. Is this really the right approach?
Or should I create the DataEvent
Object in one place outside the while loop
and reuse it when a new event should be fired?
A. I think that the answer is souly depends on what you are going to do with the object afterwords. B. Lets assume that you are just using it on the receiving end and not storing it. I would use a single object and set the fields and repost it.