eclipse-iceoryx / eclipse-iceoryx/iceoryx
Support for dynamic size types
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 492
- Avg merge
- 18h 57m
- Merged PRs (30d)
- 1
Description
## Brief feature description
At the moment it is impossible to send types in a zero copy manner which have a size that is only known at runtime. The current approach is to use a `std::vector` or similar container and copy/serialize the content into an untyped message via the untyped publisher.
I propose to adjust our containers `cxx::vector`, `cxx::string` and maybe later `cxx::(forward)list` so that they support dynamic size instead of only compile time size.
## Detailed information
The cxx containers should be extended so that a custom allocator can be attached which allocates memory inside of the shared memory.
* The extension should be done in a manner so that the capacity template parameter still works, e.g. `cxx::vector bla;` should create a vector with a stack allocator of size 10.
* The allocator should not effect function developers which are using such containers as input parameters. This would be bad: `void myFunction(cxx::vector & v);` we want `void myFunction(cxx::vector &v)` without providing the allocator type.
* Since the containers are zero copy containers the capacity has to be reserved first before filling them, otherwise intransparent copies occur due to resizing allocated memory which cannot be done in a contiguous way.
```cpp
cxx::vector myVec;
myVec.reserve(10); // only after reserve the container can be filled with elements, can be called only once
myVec.emplace_back(1234);
```
see also previous discussion in #594
## Usage example
```cpp
struct MyData {
MyData(Allocator & allocator)
: vecData(allocator), text(allocator) {}
int data;
cxx::vector vecData;
cxx::string text;
};
auto sample = publisher.loan();
sample.value()->vecData.reserve(1234); // reserve 1234 elements in vector, can be called only once
sample.value()->vecData.emplace_back(4249);
sample.value()->text.reserve(12);
sample.value()->text.assign("hello world");
sample.publish();
```
## Tasks
- [ ] Write design document
- [ ] Implement allocator which does not need to be configured, (see mempool config of roudi)
- [ ] Write example to demonstrate C++ use case with `cxx::vector` and `cxx::string`
- [ ] Write example to demonstrate in C++ a C use case
```cpp
struct MySample {
void * data;
int dataLength;
};
// use instead
struct MySample {
cxx::vector data;
};
```
## Further Information
* See #488 containers with a size of zero.
Contributor guide
Assessment
This issue has not been assessed yet.