简体   繁体   中英

Socket-based vs Unreliable messaging in Google Play Game Services

Is there a performance difference between socket-based messaging and unreliable messaging? Or the difference is just the implementation?

There should be no inherent performance difference between the two, as they are just two mechanisms that give access to the same underlying system. That said, here are a few things to keep in mind with regards to performance:

  1. Unreliable messaging requires you to provide a byte[] buffer. So don't fall into the performance pitfall of allocating a new byte buffer every time you want to send an unreliable message, because the garbage collector won't be happy.

  2. If you are using C/C++ to write your game, using sockets can be done natively, while sending unreliable messages requires a trip to Java-land via JNI. It's pretty easy to shoot oneself in the foot in the native/Java boundary, especially with regards to performance (your byte arrays might have to copied, for instance).

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