Home · All Classes · Main Classes · Deprecated |
MSharedData is a helper ilass that implements a shared memory buffer. It can have an arbitrary size and support complex data structures through serialization. Internally, MSharedData uses QSharedMemory. More...
Inherits QObject.
Public Types | |
enum | OpenMode { ReadOnly, Write } |
Public Member Functions | |
MSharedData (const QString &key, int pageSize=8192) | |
~MSharedData () | |
bool | open (OpenMode mode) |
void | close () |
QString | errorString () const |
bool | setPageSize (int pageSize) |
int | pageSize () const |
qint64 | pos () const |
bool | seek (qint64 offset) |
MSharedData & | operator<< (int i) |
MSharedData & | operator<< (bool flag) |
MSharedData & | operator<< (qreal r) |
MSharedData & | operator<< (QFont font) |
MSharedData & | operator<< (QVariant v) |
MSharedData & | operator<< (QString str) |
MSharedData & | operator<< (QByteArray array) |
MSharedData & | operator>> (int &i) |
MSharedData & | operator>> (bool &i) |
MSharedData & | operator>> (qreal &r) |
MSharedData & | operator>> (QFont &font) |
MSharedData & | operator>> (QVariant &v) |
MSharedData & | operator>> (QString &str) |
MSharedData & | operator>> (QByteArray &array) |
Protected Attributes | |
MSharedDataPrivate *const | d_ptr |
Properties | |
int | pageSize |
MSharedData is a helper ilass that implements a shared memory buffer. It can have an arbitrary size and support complex data structures through serialization. Internally, MSharedData uses QSharedMemory.
MSharedMemory is optimized in terms of its memory consumption. It uses paging to vary its size. Initially, only 1 page is allocated. However, additional pages are allocated as needed.
QSharedMemory provides a plain buffer. It is often needed to store data structures with internal pointers, for example QList. Serialization is a mechanism that allows saving such data structures to hard drives. We are employing the same mechanism to store such a data structure in a shared memory buffer. Similar to QDataStream, MSharedData provides operators << and >> to save and load complex data structures. It is possible to open MSharedData in either of two modes: ReadOnly and Write.
Even though MSharedData employs paging mechanism to facilitate gradual buffer growth, to the programmer it appears as one continuous area of memory. Therefore, functions pos() and seek() use continuous offset which always increases as more data is written into the memory, even after new pages are created.
The use case is as follows. The theme daemon creates a shared memory buffer and populates it with data:
MSharedData *shm = new MSharedData("buffer"); shm->open(MSharedData::Write); *shm << QString("data"); *shm << qVariantFromValue(QColor(Qt::white)); shm->close();
The application opens the shared buffer for reading and de-serializes the data:
MSharedData *shm = new MSharedData("buffer"); shm->open(MSharedData::ReadOnly); QString str; QVariant color; *shm >> str >> color; shm->close();
MSharedData::MSharedData | ( | const QString & | key, | |
int | pageSize = 8192 | |||
) |
A constructor. Creates a shared memory buffer with a given key.
MSharedData::~MSharedData | ( | ) |
A destructor. Detaches from every page it was attached to.
void MSharedData::close | ( | ) |
Closes the memory buffer and flushes all updated pages.
QString MSharedData::errorString | ( | ) | const |
Returns the error string. Empty if no error has occurred.
bool MSharedData::open | ( | MSharedData::OpenMode | mode | ) |
Opens the shared memory buffer for reading or for writing.
MSharedData & MSharedData::operator<< | ( | int | i | ) |
Writes integer to shared memory
MSharedData & MSharedData::operator<< | ( | bool | flag | ) |
Writes boolean to shared memory
MSharedData & MSharedData::operator<< | ( | qreal | r | ) |
Writes qreal to shared memory
MSharedData & MSharedData::operator<< | ( | QFont | font | ) |
Write QFont to shared memory
MSharedData & MSharedData::operator<< | ( | QVariant | v | ) |
Writes QVariant to shared memory
MSharedData & MSharedData::operator<< | ( | QString | str | ) |
Writes QString to shared memory
MSharedData & MSharedData::operator<< | ( | QByteArray | array | ) |
Writes QByteArray to shared memory
MSharedData & MSharedData::operator>> | ( | QVariant & | v | ) |
Reads QVariant from shared memory
MSharedData & MSharedData::operator>> | ( | bool & | i | ) |
Reads boolean from shared memory
MSharedData & MSharedData::operator>> | ( | QString & | str | ) |
Reads QString from shared memory
MSharedData & MSharedData::operator>> | ( | QFont & | font | ) |
Reads QFont from shared memory
MSharedData & MSharedData::operator>> | ( | qreal & | r | ) |
Reads qreal from shared memory
MSharedData & MSharedData::operator>> | ( | QByteArray & | array | ) |
Reads QByteArray from shared memory
MSharedData & MSharedData::operator>> | ( | int & | i | ) |
Reads integer from shared memory
int MSharedData::pageSize | ( | ) | const |
Returns the page size.
qint64 MSharedData::pos | ( | ) | const |
Returns the current offset within the shared memory buffer.
bool MSharedData::seek | ( | qint64 | offset | ) |
Sets the current offset within the shared memory buffer.
bool MSharedData::setPageSize | ( | int | pageSize | ) |
Sets the page size. The default value is 8192 bytes. Returns true if the new page size was set, false if there was an error.
MSharedDataPrivate* const MSharedData::d_ptr [protected] |
int MSharedData::pageSize [read, write] |
Copyright © 2010 Nokia Corporation | MeeGo Touch |