Update

I found this from document. ( 
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.repeated_field#RepeatedPtrField.AddAllocated.details
 
)

Add an already-allocated object, passing ownership to the RepeatedPtrField 
<https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.repeated_field#RepeatedPtrField>
.

It seems it's not possible to do what i want unfortunately.

Since Sub's value going to be a very large data like 100KB, 
so i want to avoid copying data for each Wrapping.

*How can i just toss pointer to Wrapping object without passing new 
instance's ownership?*
*I will clear up newed instance after all jobs done.*





2018년 1월 4일 목요일 오후 9시 14분 31초 UTC+9, 기준 님의 말:
>
> I'm testing protocol buffers, but encountered segment fault that i can't 
> understand.
>
> My protocol buffer is below
>
> ```
> message Sub {
>   string value = 1;
> }
>
> message Wrapping {
>   int32 key = 1;
>   repeated Sub sub = 2;
> }
> ```
>
> Testing code is below
>
> ```
> void Test()
> {
>   gbtest::Sub* sub = new gbtest::Sub();
>
>   for(int i = 0 ; i<4 ; ++i)
>   {
>     gbtest::Wrapping wrapping; // Local variable
>     wrapping.mutable_sub()->AddAllocated(sub);
>     wrapping.set_key(i);
>
>     std::cout << "Size -> " << wrapping->mutable_sub()->size() << 
> std::endl;
>   }
> }
> ```
>
>
>
>
> I want copy sub's pointer to each newed wrapping rather than copy it's 
> data.
>
>
> How can i achieve this?
> Plz tell me how.
>
> Thanks.
>
>
>
>
>
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to