CArchive::CArchive

Syntax

CArchive( CFile* pFile, UINT nMode, int nBufSize = 512, void FAR* lpBuf = NULL )
throw( CMemoryException, CArchiveException, CFileException );

Parameters

pFile

A pointer to the CFile object that is the ultimate source or destination of the persistent data.

nMode

A flag that specifies whether objects will be loaded from or stored to the archive. The nMode parameter must have one of the following values:

Value Meaning

CArchive::load Load data from the archive. Requires only CFile read permission.
CArchive::store Save data to the archive. Requires CFile write permission.

nBufSize

An integer that specifies the size of the internal file buffer, in bytes.

Note:

The default buffer size is 512 bytes. If you routinely archive large objects, you will improve performance if you use a larger buffer size that is a multiple of the file buffer size.

lpBuf

An optional FAR pointer to a user-supplied buffer of size nBufSize. If you do not specify this parameter, the archive allocates a buffer from the local heap and frees it when the object is destroyed. The archive does not free a user-supplied buffer.

Remarks

Constructs a CArchive object and specifies whether it will be used for loading or storing objects. You cannot change this specification after you have created the archive.

You may not use CFile operations to alter the state of the file until you have closed the archive. Any such operation will damage the integrity of the archive. You may access the position of the file pointer at any time during serialization by (1) obtaining the archive's file object from the GetFile member function and then (2) using the CFile::GetPosition function. You should call CArchive::Flush before obtaining the position of the file pointer.

Example

extern char* pFileName;

CFile f;

char buf[512];

if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite ) ) {

#ifdef _DEBUG

afxDump << "Unable to open file" << "\\n";

exit( 1 );

#endif

}

CArchive ar( &f, CArchive::store, 512, buf );

See Also

CArchive::Close, CArchive::Flush, CFile::Close