I am using the structured storage to backup a database (postgre & ado).
Each table of the database is a stream in my compound file.
Some tables of the database contain bytea fields to store pictures.
When I backup a table, I don't want to load the entire table in memory.
So I retreive the records by packets, I query the IPersistStream of the
recordset then I call the method OleSaveToStream. The successives calls to
the method OleSaveToStream don't grow up the memory because I create the
storage in direct mode, so the data are saved directly. This works fine !
When I restore the backup, I call the method OleLoadFromStream many times
and I notice that the memory grows up each time. Instead, if I use a stream
created with the method SHCreateStreamOnFile, I don't have this problem.
Is it possible to avoid this problem with the streams of a structured
storage ?
Here is my code, you will better understand it than my english ;)
BACKUP :
CComPtr<IStream> pIStream;
CComPtr<IStorage> pIStorage;
StgCreateDocfile(L"backup.bin",
STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE, 0, &pIStorage);
pIStorage->CreateStream(L"mytable",
STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_DIRECT, 0, 0, &pIStream);
CADORecordset rs(m_pMyDatabase); // smart pointer of _RecordsetPtr
UIN uiCount = 0;
for (;;)
{
CString sz;
sz.Format("select * from mytable limit 100 offset %d", uiCount);
if (!rs.Open(sz, CADORecordset::openQuery))
break;
if (rs.GetRecordCount() == 0)
break;
uiCount += uiRsCount;
CComQIPtr<IPersistStream> pIPS(rs.m_pRecordset);
OleSaveToStream(pIPS, pIStream);
}
BACKUP RESTORE :
CComPtr<IStream> pIStream;
CComPtr<IStorage> pIStorage;
StgOpenStorage(L"backup.bin", NULL,
STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE, 0, 0, &pIStorage);
pIStorage->OpenStream(L"mytable", 0,
STGM_READ|STGM_DIRECT|STGM_SHARE_EXCLUSIVE, 0, &pIStream);
for (;;)
{
_RecordsetPtr pRS;
pRS.CreateInstance(__uuidof(Recordset));
pRS->CursorLocation = adUseClient;
if (OleLoadFromStream(pIStream, __uuidof(_Recordset),
reinterpret_cast<LPVOID *>(&pRS)) != S_OK)
// the amount of memory grows up on each call of OleLoadFromStream. THAT'S
MY PROBLEM !! :(
// but if I use a stream created with the method SHCreateStreamOnFile, I
don't have this memory problem !
break;
// ... copy the disconnected recordset to a connected recordset ...
}
thanks a lot for your read
I hope someone can help me
Mike