.accoding to your suggestion,
i found in the class RecordSet ,RepeatedFieldPtr<Record*> record_ was
defined,and it stored its submessage :record,it alse provied
mutable_record() api ,
it just returned RepeatedFieldPtr<Record*> *
i also found when we use this api : Record *pRecordB = recordsetB-
>add_record(),it actually do this record_->Add()
so in my test ,i did like this:
recordsetB->mutable_record()->AddAllocated(pRecordA)
when i release recordsetB,first i user this api :
while(recordsetB->mutable_record()->size() > 0)
{
recordsetB->mutable_record()->releaseLast();
}
delete recordsetB;
recordsetB= NULL;
delete recordsetA;
recordsetB = NULL;
by doing this ,i'll never use copyfrom ,and it actually did!
so i have a question,actually there are two method to add pointer
record Add()、AddAllocated(),and first is public to user like us ,but
the second is not.
to avoid conflict when we release RecordSet,
we have to do one more step,if record is allocated,we use
releaseLast(),and if record is generated by itself ,we can release it
directly.
On 7月12日, 下午8时46分, Pherl Liu <
liuj...@google.com> wrote:
> 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.
>
> >
http://groups.google.com/group/protobuf?hl=en.- 隐藏被引用文字 -
>
> - 显示引用的文字 -