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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
continue
To know for sure you'd have to do a test for your particular case.
Things to keep in mind about Parcel:
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.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
Don't use Binder, because it creates a proxy (if cross-process).
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).If you use Parcel multiple times, then give it back to the pool with
recycle()
.