0

If the receiver of a request can be represented in an address space-independent way, then you can transfer a command object for the request to a different process and fulfill the request there.

from : http://www.worldcat.org/isbn/9780201633610

How can an object be represented in address space independent way in c++?

edit : How can an object be represented in address space independent way in c++ so as to enable transfer of command objects to different process and be able to fulfil the request?

q126y
  • 1,589
  • 4
  • 18
  • 50

3 Answers3

3

I don't have that Design patterns: elements of reusable object-oriented software book at hand, but I guess the author means that the algorithms should not depend on the actual values of addresses of objects.

So if you use some hash table on some key, you won't use the key's address for hashing, but some hash related to the key's contents.

You don't want the observable behavior of your program to depend upon ASLR.

To communicate with other processes, you'll better use serialization techniques and formats (e.g. JSON) and you don't want that format to depend upon actual addresses (in particular, it should never change because of ASLR).

This does not means that at the lowest level, objects don't contain addresses or pointers (since pointers are ubiquitous in C++). It simply means that you won't care about the particular numerical values of those addresses.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
2

As for your question updates:

How can an object be represented in address space independent way in c++ so as to enable transfer of command objects to different process and be able to fulfil the request?

That's done using de-/serialization for communicating any command objects to another process and an appropriate IPC technology (simplest one for the transport is socket based communication IMHO).

There are no c++ standard idiomatic solutions for de-/serialization, but google protobuf or boost::serialization are of a good assistance.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1

The paragraph you quoted is from the Command pattern, I think.

A description of the pattern can also be found on the web at various sites. E.g. https://en.wikipedia.org/wiki/Command_pattern.

The most common manifestations of the Command pattern in which the data corresponding to a command are transferred in address space independent way are:

  1. HTTP/FTP requests over the web.
  2. CORBA calls over the net.
  3. COM calls in MS Windows.

I am sure there are plenty more technologies which allow you to execute a command in a remote machine or in a different process. They can work only because a command can be represented in an address space independent way and transmitted across the net or across process boundaries.

How can an object be represented in address space independent way in c++?

If the sender and receiver of the command can agree on a representation of data for basic types such as char, int, long, float, double, they can usually use them as building blocks to enable sending and receiving of higher level objects.

R Sahu
  • 204,454
  • 14
  • 159
  • 270