ames, distributed database systems, multimedia and graphic applications use persistent objects extensively. Yet presently, C++ doesn't support persistence directly (there are proposals
for adding persistence and reflection to C++ in the future). Persistence support is not as trivial as it may seem at first. The size and memory layout of the same object may vary from one platform to another. Different byte ordering, or endian-ness
, complicate matters even further.
In this article, I will show how to implement persistence without resorting to third-party frameworks such as DCOM and CORBA. For small and portable applications, this is an effective and satisfactory solution.
To make an object persistent, we have to reserve its state in a non-volatile storage device. Consider an application that records and plays MP3 files. Every clip is represented as an object that contains the title, album, performer, time, bit-rate, recording date and the matching MP3 file. The application displays recently played tracks on the track list.
We need to to implement object persistence without resorting to third-party frameworks such as DCOM and CORBA.
Write a persistent object to retain its state outside the scope of the program in which it was created.