共用方式為


CSharedFile Class

The CMemFile-derived class that supports shared memory files.

class CSharedFile : public CMemFile

Members

Public Constructors

Name

Description

CSharedFile::CSharedFile

Constructs a CSharedFile object.

Public Methods

Name

Description

CSharedFile::Detach

Closes the shared memory file and returns the handle of its memory block.

CSharedFile::SetHandle

Attaches the shared memory file to a memory block.

Remarks

Memory files behave like disk files except that the file is stored in RAM rather than on disk. A memory file is useful for fast temporary storage or for transferring raw bytes or serialized objects between independent processes.

Shared memory files differ from other memory files in that memory for them is allocated with the GlobalAlloc Windows function. The CSharedFile class stores data in a globally allocated memory block (created using GlobalAlloc), and this memory block can be shared using DDE, the Clipboard, or other OLE/COM uniform data transfer operations, for example, using IDataObject.

GlobalAlloc returns an HGLOBAL handle rather than a pointer to memory, such as the pointer returned by malloc. The HGLOBAL handle is needed in certain applications. For example, to put data on the Clipboard you need an HGLOBAL handle.

Please note that CSharedFile does not use memory-mapped files, and the data cannot be directly shared between processes.

CSharedFile objects can automatically allocate their own memory or you can attach your own memory block to the CSharedFile object by calling CSharedFile::SetHandle. In either case, memory for growing the memory file automatically is allocated in nGrowBytes-sized increments if nGrowBytes is not zero.

For more information, see the article Files in MFC and File Handling in the Run-Time Library Reference.

Inheritance Hierarchy

CObject

CFile

CMemFile

CSharedFile

Requirements

Header: afxadv.h

See Also

Reference

CMemFile Class

Hierarchy Chart

CMemFile Class

GlobalAlloc

GlobalFree

GlobalRealloc