I s it possible to develop a distributed memory pointer in C++ by using operator overload?
The idea would be that you pass ip address and port to the overloaded pointer *, &, and the pointer returns the memory location of remote computer.
I s it possible to develop a distributed memory pointer in C++ by using operator overload?
The idea would be that you pass ip address and port to the overloaded pointer *, &, and the pointer returns the memory location of remote computer.
Yes, C++ provides you with awesome powers, and itty bitty living spaces.
Break your problem down first.
You need a Connection
object responsible for handling the nitty gritty of communication. It would handle network addresses and whether its using udp, tcp or something else.
You need a Proxy
object responsible for marshalling the object itself, or interactions with that object across some Connection
. It would be wise to use an asynchronous style to handle interactions.
You will need a FlyWeight of some kind to act as that particular Objects representative in local memory. Call it something other than flyweight though. This object will be responsible for managing the interaction across the Proxy
, this might include managing a local cache from which to short-circuit the answer from. If necessary it will also be responsible for turning the asynchronous into synchronous function calls.
At this point you no longer need to role your own pointer, just aim unique_pointer
, or shared_ptr
at your flyweight.
The only caveat is cleanup. If for some reason your flyweight controls the lifetime of the remote object you will have to consider how you are going to manage that. A Destructor cannot just wait around for a network request to complete, otherwise you place the behaviour of your own program in jeopardy. To work around this you will need to consider using some form of Garbage Collector which has a way to determine if the object is no longer in use, and properly arrange for cleanup.
The answer is yes and no:
->
could send commands to the remote component. The operator*
could even get a local copy of the remote object.