Topic: vtbl in persistent object
Author: Rob Stewart <donotspamme@giage.com>
Date: 1998/02/11 Raw View
This is a multi-part message in MIME format.
--------------B6B1E4B52F9F0995F9886E3E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Delarue Christophe wrote:
> We would like to have persistent object, in file for example. Thus we allocate
> space in a special area and call the Constructor on this area.
> Suppose the system goes down. The object are saved in the file.
> The system restart and the persistent area of memory is restored. We have tagged
> the objects thus we are able to know what object is at what place. The content
> is well restored.
>
> BUT
>
> The problem is for the vtbl field of the objects. The only solution we found is
> to call a special constructor on this area of memory to restore the value
> corresponding to the value of the current software version of the class. Thus
> different version of software (with no change of the size of object) can work.
I had that problem years ago. My solution was to use the copy constructor or copy
assignment to create a new object with the values from the incompletely restored
object. IOW, after restoring the persistent object, the vtbl is wrong. However, copy
the state of that object to another object created within the current process merged
the desired state with the correct vtbl.
CAUTION: If the copy ctor or copy assignment op invokes virtual functions on the
object you're copying from, you're in trouble. You would have to ensure that the
function calls were non-virtual (scope resolution would work, for example) or avoid
them in the copy ctor and copy assignment operator.
--
Robert Stewart | rob@giage.com
Software Engineer | using std::disclaimer;
Giage, Ltd.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Delarue Christophe <cdelarue@lucent.com>
Date: 1998/02/09 Raw View
We would like to have persistent object, in file for example. Thus we allocate
space in a special area and call the Constructor on this area.
Suppose the system goes down. The object are saved in the file.
The system restart and the persistent area of memory is restored. We have tagged
the objects thus we are able to know what object is at what place. The content
is well restored.
BUT
The problem is for the vtbl field of the objects. The only solution we found is
to call a special constructor on this area of memory to restore the value
corresponding to the value of the current software version of the class. Thus
different version of software (with no change of the size of object) can work.
I read that the vtbl is stored in the two first bytes of a object. Is this
mandatory ? Is this respected by all compiler ? Is this a standard ?
Thank's for help.
--
Christophe DELARUE LUCENT Technologies
mailto:cdelarue@lucent.com
http://www-bcsbl.fr.lucent.com/~delarue
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/02/10 Raw View
Delarue Christophe wrote:
...
> I read that the vtbl is stored in the two first bytes of a object. Is this
> mandatory ? Is this respected by all compiler ? Is this a standard ?
The standard doesn't specify the size of the vtbl. It doesn't require
that it even exist. In fact, the standard doesn't mention vtbl's at
all. That is an implementation detail, and there are several different
ways to do it, and several ways to implement C++ without using a vtbl.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]