发布于 2024-11-07 16:56:59 字数 242 浏览 0 评论 0原文

Would it be a good idea to use protocol buffer objects (serialized to byte arrays) to pass as intent extras between Android activities instead of implementing Parcelable on classic POJOs? How would it affect performance?

谢谢 马库斯

Would it be a good idea to use protocol buffer objects (serialized to byte arrays) to pass as intent extras between Android activities instead of implementing Parcelable on classic POJOs? How would it affect performance?

Thanks
Markus

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多彩岁月 2024-11-14 16:56:59

continue

To know for sure you'd have to do a test for your particular case.

Things to keep in mind about Parcel:

  1. As you may know, it's a manual process: you have to walk your object tree and call Parcel's various serialization method, e.g. writeFloatArray(..). There is no magic and it is as low-level as it gets.

  2. Parcel.java is a wrapper around native implementation, so it should be pretty optimized already: http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/libs/binder/Parcel.cpp&q=Parcel.cpp%20package:android&sa=N&cd=1&ct=rc

  3. Don't use Binder, because it creates a proxy (if cross-process).

  4. Probably most important: size the initial buffers properly with setDataCapacity(int size). This way internal array will not need to be grown (= memory alloc + copy).

  5. If you use Parcel multiple times, then give it back to the pool with recycle().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文