Topic: VIRTUAL MEMORY ARRAYS IN C++


Author: nevries@cs.ruu.nl (Nico de Vries)
Date: 5 Sep 91 11:33:58 GMT
Raw View
I wany your response to the following problem.

Suppose I want to make a virtual array in C++. Virtual in the sense
parts or all of it can reside on disk. Of cource I want the virtual
array to mimic a normal array as much as possible.

Implementations I have seen so far, for example the virtual
array class in C++ TOOLS from Zortech. Simply overload the
[] operator to return a reference to the element. Before
the reference is returned it is assured to reside in memory.
At a later moment the element is swapped to disk invalidating
the reference returned by the [] operator.
The invalidation of the reference doesn't seem to be a problem
in e.g. a=v[33]  Imidiately after the operator call it is
dereferenced. In the expression v[33]=... I expect a problem.
What if the operator= function decides to evaluate v[33] first,
and the ... part somehow invalidates the reference (e.g. by
accessing lots of other elements.

I have thought of a few ways to improve this method and like
your oppinion.

1) defining a new class ACCESSOR which holds a reference to
   a virtual arrau and an index. The [] operator constructs
   an accessor object. The = operator is overloaded to call
   eReadElement and eWriteElement whan used with an accessor.
   The = operator also destructs the accessor element.
Obvious is that this is an inefficient solution. Also it
doesn't make using array elements as parameters to functions
any easieer.
2) somehow assure the = operator first evaluates the seccond
   element and afterwards the first element.
I don't know any easy ways to achieve this and this also
doesn't solve the parmeter passing problem (I am aware
however the parameter passing problem is much complexer
and would settle for a neat assignment only solution).
3) allow only read/write calls, no references at all
e.g.   a=v(3)   v(3,....)
solves the problem but isn't compatible
4) ANYONE having better ideas???

Nico de Vries