Let's say I have a process written in C++ that has many instances of class A.
class A {
std::vector<std::vector<short>> tab;
/* other random data */
}
Once created, these objects should be accessed (read-only) by other processes of a different application, also in C++.
I would like to avoid at all cost making copies or moving the objects as it would significantly increase the memory consumption and probably take more time.
A 'simple' portable solution would be to serialize the objects in a shared memory and then when asked for the data, the process would just give the location of the various instances of class A in memory, and the second process would deserialize them before being able to read the data. That means that we would create a copy each time a process wants to read the data. This is what I would like to avoid.
Given that both processes are written in C++ and both know the definition of the class A, is it possible to avoid the serialization and therefore copy/displacement of the data ? Of course it would not be portable anymore but it does not need to be.
Can a simple static_cast through the shared memory allow the second process to read the data in it as its own without making any processing of any kind therefore costing no time and no additional memory at all ?
If not, is there a simpler form of serialization adding just an overhead that would allow the second process to understand and read the data without having to make a copy ?