I want to know which of the following implementation is better in
terms of performance and usability. Option A is much easier and
portable across different protobuf versions. Is it worth the trouble
trying to go with Option B? In my tests, I could not find much of a
performance gain by using Option B.

Option A uses the protobuf compiler generated class to loop through
each elements of a repeated doubles.
On the other hand, Option B uses RepeatedField class to extract a
pointer to the array of doubles.

Option A:
int size = bucket.bucketdouble(j).data_size();
double* doubleVector = new double[size];
for(int k=0; k<size; k++) {
    doubleVector[k] = bucket.bucketdouble(j).data(k);
// Custom function that takes arrays of doubles
add_double_vector(doubleVector, size);
delete [] doubleVector;

Option B:
using namespace google::protobuf;
DoubleData* doubledata_m = deal_pb.mutable_bucket(i)-
RepeatedField< double >* doublearray_m = doubledata_m->mutable_data();
// Custom function that takes arrays of doubles
add_double_vector(doublearray_m->mutable_data(), doublearray_m-

My .proto file looks something like this:
message DoubleData {
    required string name = 1 [default = "noname"];
    repeated double data = 2;

message Bucket {
   repeated DoubleData bucketDouble = 2;

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to