moving objects to shared memory

Hello,

I am not so experianced with c++ myself, but I need to evaluate if a certain idea might work.

I am working with a system for automation purposes that is running on a realtime OS in parallel to windows. Windows and the RTOS exchange data via shared memory. The application in the RTOS is compiled in C++. Now I would like to be able to influence the some data manipulation tasks in the RTOS application without changing the code of the RTOS application. So a concept like calling a dll.

My idea was to create a class with virtual methods in the RTOS application. The objects that are used should then be created on the Windows side with the same class prototype, but specific implementation of the virtual methods. The objects should then be moved to the shared memory, where they are used by the RTOS application.

Is something like this possible or am I completly on the wrong path?

Help on this topic would be very much appreciated.

Thanks
The virtual table pointer and the virtual table are in the address space of the process that constructs the object, so if we place a class with a virtual function or virtual base class, the virtual pointer placed in shared memory will be invalid for other processes and they will crash.

This problem is very difficult to solve, since each process needs a different virtual table pointer and the object that contains that pointer is shared across many processes. Even if we map the mapped region in the same address in every process, the virtual table can be in a different address in every process. To enable virtual functions for objects shared between processes, deep compiler changes are needed and virtual functions would suffer a performance hit. That's why Boost.Interprocess does not have any plan to support virtual function and virtual inheritance in mapped regions shared between processes.

http://www.boost.org/doc/libs/1_53_0/doc/html/interprocess/sharedmemorybetweenprocesses.html
Thank you very much for the explaination.

Are there any other possible solutions for my problem?
> Now I would like to be able to influence the some data manipulation tasks
> in the RTOS application without changing the code of the RTOS application.

The data can safely be placed into shared memory, it is the code that would be there only in the windows program. So,

1. separate the code from the data. Something like:

1
2
3
4
5
6
7
8
struct foo_data { /* ... */ } ;

struct foo
{
      // implement the operations
     
      offset_ptr<foo_data> data ; // smart pointer to shared memory
}; 


2. create an RTOS side surrogate

1
2
3
4
5
6
7
struct foo_client
{
      // forward the operations to the windows side surrogate
      // using a suitable IPC mechanism 
     
      offset_ptr<foo_data> data ; // smart pointer to shared memory
}; 


3. create an windows side surrogate

1
2
3
4
5
6
7
8
struct foo_server
{
      // listen for requests from the RTOS side surrogate
      // forward to  impl_on_windows 
     
      offset_ptr<foo_data> data ; // smart pointer to shared memory
      shared_ptr<foo> impl_on_windows ; // windows side only
};



For the IPC mechanism you could use shared memory (which you already have), boost::mpi (light and extremely efficient) or just BSD sockets (which everyone supports)
Thank you for the hint.
I will look into this.
Topic archived. No new replies allowed.