Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ and persistent objects

Reply
Thread Tools

C++ and persistent objects

 
 
Perry St-Germain
Guest
Posts: n/a
 
      11-18-2003
Typically C++ persistence implementations, (from the little I've seen),
boils down to something like this:

myclass {
int ivar;
float fvar;
...

saveyourself( file )
{
file.write(ivar);
file.write(fvar);
...
}

};

With this approach we always have to write the code to unwind the variables
to or from the storage media. This can be a big job for objects that involve
complex class hierarchies, and it could impact performance as well.

Another approach is to write/read binary chunks and then use inplace
activation techniques. This is better but what happens when the structure
changes ..., then you need to write conversion functions and you end up
writing code similar to the above where you need to unwind the variables
again.

I'm thinking there must be a better way. After all isn't this exactly what
COM and Corba or XML does to marshal an interface or data structure. With
these frameworks you generally don't have to do the unwinding code yourself
there is typically a tool that does it for you. Is there a way to leverage
these tools to solve the C++ persistence problem, or perhaps there is some
other code available? Am I missing something here?


Any suggestions or links?

Thanks,
Perry.






 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      11-18-2003
Perry St-Germain wrote:
> Typically C++ persistence implementations, (from the little I've seen),
> boils down to something like this:


Ah - a favorite topic of mine ...

These are a couple of URL's to google past comp.lang.c++ posts on this
topic.

http://tinyurl.com/vgbc
http://tinyurl.com/vgbs


>
> myclass {
> int ivar;
> float fvar;
> ...
>
> saveyourself( file )
> {
> file.write(ivar);
> file.write(fvar);
> ...
> }
>
> };
>
> With this approach we always have to write the code to unwind the variables
> to or from the storage media. This can be a big job for objects that involve
> complex class hierarchies, and it could impact performance as well.
>
> Another approach is to write/read binary chunks and then use inplace
> activation techniques. This is better but what happens when the structure
> changes ..., then you need to write conversion functions and you end up
> writing code similar to the above where you need to unwind the variables
> again.
>
> I'm thinking there must be a better way. After all isn't this exactly what
> COM and Corba or XML does to marshal an interface or data structure. With
> these frameworks you generally don't have to do the unwinding code yourself
> there is typically a tool that does it for you. Is there a way to leverage
> these tools to solve the C++ persistence problem, or perhaps there is some
> other code available? Am I missing something here?
>
>
> Any suggestions or links?
>


I have found that the fastest form of IO on almost any platform is a
mapped file. C++ has no built-in support for mapped files so you're in
OS dependant land but this is a very thin layer.

You could theoretically make a "portable" format for mapped files that
works on a large subset of computing platforms today.


 
Reply With Quote
 
 
 
 
Jeff F
Guest
Posts: n/a
 
      11-18-2003

"Perry St-Germain" <(E-Mail Removed)> wrote in message
news:yjfub.33799$(E-Mail Removed). ..
> Typically C++ persistence implementations, (from the little I've seen),
> boils down to something like this:
>
> myclass {
> int ivar;
> float fvar;
> ...
>
> saveyourself( file )
> {
> file.write(ivar);
> file.write(fvar);
> ...
> }
>
> };


This is serialization, which can be used to implement persistence. Join the
boost.org development mailing list where Robert Ramey is refining an
implementation which he is planning on submitting to boost. He's separated
the medium ( text/binary/xml/... archives ) from the serialization
machinery. His library supports both non-intrusive as well as intrusive
serialization capabilities.

> With this approach we always have to write the code to unwind the

variables
> to or from the storage media. This can be a big job for objects that

involve
> complex class hierarchies, and it could impact performance as well.


I assume by "unwinding" you mean "load"? You may handle load/store with a
single serialize function ala:

template<class Archive>
void serialize( Archive &ar, unsigned int version )
{
ar & ivar;
ar & fvar;
}

> Another approach is to write/read binary chunks and then use inplace
> activation techniques. This is better but what happens when the structure
> changes ..., then you need to write conversion functions and you end up
> writing code similar to the above where you need to unwind the variables
> again.
>
> I'm thinking there must be a better way. After all isn't this exactly what
> COM and Corba or XML does to marshal an interface or data structure. With
> these frameworks you generally don't have to do the unwinding code

yourself
> there is typically a tool that does it for you. Is there a way to leverage
> these tools to solve the C++ persistence problem, or perhaps there is some
> other code available? Am I missing something here?



The only systems of this ilk that I know of are:

http://www.cs.utexas.edu/users/oops/papers.html#texas

Which is a research project at university of texas. I haven't seen any work
done on this in quite some time.

http://www.objectstore.net/products/index.ssp

A commercially available system. Quite powerful/large/complex, but does what
your asking for.

What these systems generally require is some sort of external definition
language akin to COM's IDL. IMO this is a major drawback, requiring
knowledge of another language and maintenance of another set of code. Bjarne
Stroustrup has a paper on XTI - Extended Type Information Library - that
possibly could negate the need for this redundancy.

Persistence is much more complex than one first imagines. Robert Ramey's
serialization library, IMO is the most comprehensive, easiest to use and
least expensive(free) alternative that I've seen.

-----------------
Jeff Flinn
Applied Dynamics, International



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Persistent field and Persistent properties - difference gk Java 7 10-12-2010 09:43 PM
Re: Persistent Distributed Objects bouncyinc@gmail.com Python 2 10-10-2009 09:40 AM
querying persistent ruby objects in memory braver Ruby 2 05-26-2007 10:33 PM
How can i have persistent objects in the server side? gnufied Ruby 1 05-26-2006 09:13 AM
Persistent objects Paul Rubin Python 16 12-14-2004 09:50 AM



Advertisments