viaches
asked on
C++ objects with virtual function and UNIX shared memory
I want to make some objects in shared memory. These objects have got virtual functions. The first process (server) makes shared memory and objects in it. Other processes attach this memory and use objects. Can I make these processes not copy or fork of server process?
For example:
class a {
public:
virtual void func();
};
class b : public a {
virtual void func();
};
...
Server:
char *ptrshare; // pointer to shared memory
a *ptra=new a;
b *ptrb=new b;
...
memcopy(ptrshare,ptra,size of(a));
ptrshare+=sizeof(a);
memcopy(ptrshare,ptrb,size of(b));
ptrshare+=sizeof(b);
...
Client :
char *clientptrshare;
a *ptra=(a *)clientptrshare;
ptra->func(); // ?!!!
I tried this in HP UX. class a was in module a.cpp,
b - b.cpp etc.
If I make programs:
CC server.o a.o b.o c.o -o server
CC client.o a.o b.o c.o -o client
That's OK.
CC server.o a.o b.o c.o -o server
CC client.o a.o c.o b.o -o client
That's wrong.
For example:
class a {
public:
virtual void func();
};
class b : public a {
virtual void func();
};
...
Server:
char *ptrshare; // pointer to shared memory
a *ptra=new a;
b *ptrb=new b;
...
memcopy(ptrshare,ptra,size
ptrshare+=sizeof(a);
memcopy(ptrshare,ptrb,size
ptrshare+=sizeof(b);
...
Client :
char *clientptrshare;
a *ptra=(a *)clientptrshare;
ptra->func(); // ?!!!
I tried this in HP UX. class a was in module a.cpp,
b - b.cpp etc.
If I make programs:
CC server.o a.o b.o c.o -o server
CC client.o a.o b.o c.o -o client
That's OK.
CC server.o a.o b.o c.o -o server
CC client.o a.o c.o b.o -o client
That's wrong.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.