Size-wise, the only difference between your "Lite" structure and the current protobuf classes is that it wouldn't have a virtual table pointer or a cached byte size. Do these really make that much difference?
On Wed, Dec 17, 2008 at 9:11 PM, Shaun Cox <shaun8...@gmail.com> wrote: > > As stated by previous posts (the uint16 one in particular), protobuf C+ > + is not designed for extremely-memory-constrained systems. I was > curious about the decision to not make the "bare bones" structure of > the message public and provide a way to construct one from another. > For example right now the generated code looks something like this: > couch.proto: > message Couch > { > required uint32 width; > required uint32 length; > } > > couch.pb.h: > class Couch : public ::google::protobuf::Message { > public: > Couch(); > // rest of public interface... > private: > // pb data members > uint32 width_; > uint32 length_; > // more pb data member > }; > > If pb provided a "bare bones" structure it might look something like: > couch.pb.h: > class Couch : public ::google::protobuf::Message { > public: > struct Lite { > Lite(const Couch& from); > uint32 width_; > uint32 length_; > }; > Couch(); > Couch(const Couch::Lite& from); > // rest of public interface... > private: > // pb data members > Lite impl_; > // more pb data member > }; > > First off, the API for constructing one from another is more just to > show an example than anything else. Exposing the underlying structure > allows you to store smaller in-memory copies of the message. This > comes into play more when the structure is part of a larger class that > isn't going across the wire. > > class LivingRoom { > Couch::Lite couches[10]; > }; > class Apartment{ > LivingRoom rooms[3]; > }; > class Complex { > Apartment apartments[10000]; > }; > class City { > Complex complexes[100000]; > } > > It seems wasteful to have Couch when you could just as well have > Couch::Lite. With a change like this, if you aren't as concerned with > memory usage, there is no change to how pb behaves or how you use > it. > > Shaun > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~----------~----~----~----~------~----~------~--~---