Qt Toolkit - QMemoryFile Class

| Classes - Annotated - Tree - Functions - Home - Structure

# QMemoryFile Class Reference

The QMemoryFile class provide means to map a file info memory or refere to a block or memory by name. More...

`#include <qmemoryfile_p.h>`

List of all member functions.

## Public Members

- enum Flags { Write = 0x00000001, Shared = 0x00000002, Create = 0x00000004, }
- QMemoryFile ( const QString & fileName, int flags=-1, uint size=0 )
- ~QMemoryFile ()
- bool isShared ()
- bool isWritable ()
- uint size ()
- char* data ()

## Detailed Description

The QMemoryFile class provide means to map a file info memory or refere to a block or memory by name.

Warning: This class is not part of the Qt APi and subject to change. This file file may change from version to version without notice, or even be removed.

Currently this class supports read only access on all platforms; and read plus write accces provided on unix and windows based plaforms. The size of mapped file can not be changed.

## Member Function Documentation

### QMemoryFile::QMemoryFile ( const QString & fileName, int flags=-1, uint size=0 )

Construct a memory mapped to an actual file or named memory block. If fileName is not preceeded by an \\ then it is treated as a real file name. Otherwise the characters after the \\ are used as the name for the memory block required. nb: You will need to escape the \'s so it you need to use \\\\ within a literal string A value for size should always be provided, though if the size is not provided it will be determined if possible.

If a file is being mapped to be written to, then the flags of subsequent QMemoryFiles mapped to the same file should include QMemoryFile::Write.

Example:

     // Open a maping to file text.dat
     QMemoryFile memoryFile("text.dat", QMemoryFile:Read, 20);
     char *data = memoryFile.data();
     int sum = 0;
     for (int i = 0; i < 20; i++){
       sum = sum + data[i];
     }
     qDebug("Sum =%d", sum);

Example for creating named memory block:

     QMemoryFile block1("\\\\block1", QMemoryFile::Create | QMemoryFile::Write, 20);
     char *dataBlock = block.data();
     for (int i = 0; i < 19; i++){
       dataBlock[i] = i +'a';
     }
     dataBlock[20] = '\0';
     qDebug("Data block is %s", dataBlock);

### QMemoryFile::~QMemoryFile ()

Destructs the memory mapped file.

### char* QMemoryFile::data ()

Returns a pointer to memory that this QMemoryFile is associated with.

### bool QMemoryFile::isShared ()

Returns true if memory is shared.

### bool QMemoryFile::isWritable ()

Returns true if memory is writable.

Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):

This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.