In C++ protobuf, each message owns its fields. That said, two different
messages cannot share a sub-message, which will complicate the system when
releasing resources.

In your case, if you always need to copy the records, there may be a better
design. For instance, keep the records in a global pool, and change the
RecordSet to only contain the ids, i.e. change the repeated Records into
repeated int32. Also if you don't need to use them simultaneously, you can
use add_allocated_record() and swap.

On Sun, Jul 10, 2011 at 4:04 PM, [email protected] <[email protected]>wrote:

> hello:
>
> we defined two object in field.proto
> message Record{
> optional int id = 1;
> }
> message RecordSet{
> repeated Record record= 1;
> }
>
> so when we define a Record pointer,we do like this:
> RecordSet recordsetA,recordsetB;
> Recrod *pRecordA = recordsetA.add_record();
> pRecordA->set_id(111);
>
> actually ,recordsetB has the same member as fieldsetA,we can only do
> like this:
> Record *pRecordB = recordsetB.add_record();
> pRecordB->CopyFrom(*pRecordA);
>
> we found that it cost  much time to  copy.
>
> if there is this method,we can solve this problem:
>
> recordasetB.add_record(pRecordA);
>
> in this way ,we don't need to copy。
>
> i've read topic in this forum, add_record() this api just for thread
> safe and don't worry about the pRecordA being accidently changed。
>
> so hope for your answer.
>
> thans!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to [email protected].
> 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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected].
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