How can be an array of double (1D) stored using protocol buffer? What about multi-dimensional (2D or 3D) dense arrays?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Sum multidimensional array C#
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
One could simply mimic the C/C++ memory layout:
To access the data, use
data[i*cols+j]
(row-major), ordata[i+rows*j]
(column-major). For square matrices only one ofrows
/cols
has to be stored. Technically even in the rectangular case protobuf will know the length of the data, and the other value can be derived.For ease of use one would probably wrap the Matrix in C++ with an Adapter class that allows access via
double MatrixAdapter::get(int row, int col)
; it could also verifydata_size()==rows()*cols()
.An array of double would be best stored via
repeated
makes it act as a list, allowing multiple items;packed
avoids a header per item.There is no direct support for rectangular (or higher) arrays in protobuf. The closest is to store something like:
this is broadly akin to a jagged array, but with an element between each tier.