Solved

IStorage and IStream

Posted on 1998-11-04
2
603 Views
Last Modified: 2013-11-20
Does anyone know good artical's or books ( downloadable articles prefered! ) about persistancy?
Can i create storegs diffrent then binary files? can my storage be textual?
0
Comment
Question by:shaig
  • 2
2 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 100 total points
ID: 1324181
Yes, you can create any kind of storages. Infact you can implement all four types of object persistence in your control. But thats not considered good COM programming technique.

I have found "Inside OLE / Kraig Brockschmidt.—2nd Edition" book to be very helpful in this. Check out chapter 8 on Persistent Objects. And this book is available online on MSDN site.

0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 1324182
Here is the page which explains the multiple persistence stuff.


Objects with Multiple Persistence Models

Any object can, as it sees fit, implement multiple persistence models by implementing a combination of the four IPersist* interfaces. However, each of these interfaces is considered mutually exclusive in that a client will use only one of them, depending on the client's prioritization of each model.

Generally speaking, IPersistStorage is the most powerful of the four interfaces, so a client might ask for it first when attempting to save or reload an object. However, storage-based persistence is expensive, so a client might request IPersistStreamInit or IPersistStream, and then IPersistStorage. Or it can give IPersistFile preference over the others.

Regardless of the client's prioritization, it must use only one of the interfaces with any given instance of an object, although it is allowed to use a different interface with different instances. The object must enforce this rule by remembering which interface was used to initialize it. If IPersistStorage::InitNew or IPersistStorage::Load has been called, the object must fail any calls to IPersistStream[Init] and IPersistFile. If IPersistStream[Init]::Load or IPersistStreamInit::InitNew has been called, the object fails calls to IPersistStorage and IPersistFile, and so on.

Remember that an object implementing all of these interfaces can use them to implement each other regardless of what the client does. For example, an implementation of IPersistFile can open a compound file and pass the IStorage pointer to its own IPersistStorage implementation, which may in turn do little more than open streams and pass them to IPersistStream. In this way, objects can support as many persistence models as they like without having a lot of redundant code.

Furthermore, an object's implementations of IPersistStorage and IPersistStream[Init] are completely independent of how the client obtains IStorage and IStream pointers. The client might be passing pieces of a storage hierarchy created on an ILockBytes, or it might pass an IStream implemented on a piece of global memory or some other medium. The object cannot assume that the storage and stream elements refer to a portion of a compound file in which a stream is at least 512 bytes. A stream implemented on a database field may be only 10 bytes by default, so writing 500 bytes of information to it can potentially fail if there is no more memory or no more space in the storage medium. This is why IPersistStorage::InitNew should call IStream::SetSize after opening the stream. This is not necessary with IPersistStream[Init], however, because the client is responsible for preallocating any streams based on what objects return from IPersistStream::GetSizeMax.


0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 114
Folder Comparison 12 52
countEvens challenge 2 59
Not needed 13 57
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now