1

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.

2
  • 4
    Anything is possible given enough time, money and pixie dust. Commented Nov 12, 2019 at 23:15
  • 1
    This is the same problem as RMI: hiding behind simple method invocation, where every operation could fail, but it is not obvious. Hiding very important details from the abstraction-consuming programmer makes things easy when things work, but very error prone and erratic in more trying situations such as network failure.
    – Erik Eidt
    Commented Nov 13, 2019 at 4:17

2 Answers 2

2

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.

2

The answer is yes and no:

  • Yes, you can create a distributed pointer that could be based on an IP address and a port. It would be implemented using the remote proxy design pattern but with a pointer interface. The operator -> could send commands to the remote component. The operator* could even get a local copy of the remote object.
  • No Your distributed pointer would not really point to a remote memory location. It just behaves as it would. Memory addresses are local to the process. Another process on the same machine already has a different address space, so imagine another process on another machine. The remote proxy could foresee a function to get the address of the remote object in the remote process address space, but you could not use it to directly access this object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.