简体   繁体   English

Google Play游戏服务中基于套接字的消息传递与不可靠的消息传递

[英]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. 不可靠的消息传递要求您提供一个byte []缓冲区。 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. 如果您使用C / C ++编写游戏,则可以本地使用套接字,而发送不可靠的消息则需要通过JNI到Java领域。 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). 在本机/ Java边界中涉足是非常容易的,特别是在性能方面(例如,可能必须复制字节数组)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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