Re: [protobuf] Shall I put protobuf message in unique_ptr to avoid copy?

2020-09-09 Thread 'Adam Cozzette' via Protocol Buffers
That sounds like a reasonable way to do it. Another thing you could do is
that if you know how big the vector will be, you can call
indexVector.reserve() to reserve the correct size, then add each element
with indexVector.emplace_back() and initialize its fields in place. That
would let you use std::vector without any extra copying.

On Wed, Sep 9, 2020 at 3:48 AM river  wrote:

> here is my code, should I directly usage vector ?
> std::vector> ret; // IndexVector is a
> protobuf message type, sizeof ... = 72
>
> while (result.next()) {
> std::unique_ptr indexVector
> {std::make_unique()};
> int64_t poiId = result.getLLong(1);
> int64_t pictureId = result.getLLong(2);
> bool isDel = result.getInt(3) != 0;
>
> indexVector->set_id(pictureId);
> indexVector->set_poiid(poiId);
> indexVector->set_isdel(isDel);
>
> ret.push_back(indexVector);
> }
> return ret;
>
> --
> 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 protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/ba2870b6-c2ac-4d3c-89b6-4ea8f2cfcba4n%40googlegroups.com
> 
> .
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr6T-9%2B0ujnDwe%3DU47Rp49tRayXMMoy8qLOC65fboGRjmQ%40mail.gmail.com.


[protobuf] Shall I put protobuf message in unique_ptr to avoid copy?

2020-09-09 Thread river
here is my code, should I directly usage vector ?
std::vector> ret; // IndexVector is a 
protobuf message type, sizeof ... = 72

while (result.next()) {
std::unique_ptr indexVector 
{std::make_unique()};
int64_t poiId = result.getLLong(1);
int64_t pictureId = result.getLLong(2);
bool isDel = result.getInt(3) != 0;

indexVector->set_id(pictureId);
indexVector->set_poiid(poiId);
indexVector->set_isdel(isDel);

ret.push_back(indexVector);
}
return ret;

-- 
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 protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/ba2870b6-c2ac-4d3c-89b6-4ea8f2cfcba4n%40googlegroups.com.