简体   繁体   中英

Re-using event object with Eventbus

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM