3

I have a simple message which contains lots of repeated numeric fields:

syntax = "proto3";
option cc_enable_arenas = true;
message bigData{
    repeated double info = 1;
}

During runtime the data arrives already allocated. This is how I attempted to encapsulate it into the message(using arena):

void set_data(std::unique_ptr<double[]> table, int size, bigData* message){ /* suppose message is valid */
    google::protobuf::Arena arena;
    google::protobuf::Arena::CreateArray<double>(&arena,size); /*(0)*/
    message->clear_info();
    for (int i = 0; i < size; i++) {
        net->mutable_info()->Add(table[i]);
    }
}
  • Is this the correct usage?
  • Is there a way to tell the arena that this already allocated data belongs to an already initialized message?
  • Is there a way to tell the arena that the memory I'm about to allocate at (0) already exists?
  • How can I minimize unneccessary data allocation/deallocation?

Update:* A related issue opened up by @Azmisov: https://github.com/protocolbuffers/protobuf/issues/8817

Dávid Tóth
  • 2,788
  • 1
  • 21
  • 46

0 Answers0