The CMemFile-derived class that supports shared memory files.
class CSharedFile : public CMemFile
|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.|
Memory files behave like disk files. The difference is, a memory 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
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.
CSharedFile doesn't use memory-mapped files, and the data can't 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 isn't zero.
CSharedFile object and allocates memory for it.
CSharedFile( UINT nAllocFlags = GMEM_DDESHARE | GMEM_MOVEABLE, UINT nGrowBytes = 4096);
Flags indicating how memory is to be allocated. See GlobalAlloc for a list of valid flag values.
The memory allocation increment in bytes.
Call this function to close the memory file and detach it from the memory block.
The handle of the memory block that contains the contents of the memory file.
You can reopen it by calling SetHandle, using the handle returned by Detach.
Call this function to attach a block of global memory to the
void SetHandle( HGLOBAL hGlobalMemory, BOOL bAllowGrow = TRUE);
Handle to the global memory to be attached to the
Specifies whether the memory block is allowed to grow.
If bAllowGrow is nonzero, the size of the memory block is increased as necessary, for example, if you attempt to write more bytes to the file than the size of the memory block.