On Mon, Dec 8, 2008 at 1:16 PM, Kenton Varda <[EMAIL PROTECTED]> wrote:

> On Sat, Dec 6, 2008 at 1:03 AM, Alek Storm <[EMAIL PROTECTED]> wrote:
>
>> Is it really that useful to have ByteSize() cached for repeated fields?
>> If it's not, we get everything I mentioned above for free.  I'm genuinely
>> not sure - it only comes up when serializing the message in wire_format.py.
>> What do you think?
>>
>
> Yes, it's just as necessary as it is with optional fields.  The main
> problem is that the size of a message must be written before the message
> contents itself.  If, while serializing, you call ByteSize() to get this
> size every time you write a message, then you'll end up computing the size
> of deeply-nested messages many times (once for each outer message within
> which they're nested).  Caching avoids that problem.
>

Okay, then we just need to cache the size only during serialization.  The
children's sizes are calculated and stored, then added to the parent's
size.  Write the parent size, then write the parent, then the child size,
then the child, on down the tree.  Then it's O(n) (same as we have
currently) and no ownership problems, because we can drop the weak reference
from child to parent.  Would that work?

Cheers,
Alek Storm

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to