예제 #1
0
void KisMemoryWindowTest::testTopReports()
{

    // default window size in 16 MiB
    KisMemoryWindow memory(QString(QDir::currentPath()), DEFAULT_WINDOW_SIZE);

    // write 1024 chunks 4 MiB each, hi-limit 4GiB

    const quint8 oddValue = 0xee;
    const qint64 chunkLength = 4 * MiB;

    QScopedArrayPointer<quint8> writeBuffer(new quint8[chunkLength]);
    memset(writeBuffer.data(), oddValue, chunkLength);

    QScopedArrayPointer<quint8> readBuffer(new quint8[chunkLength]);

    qint64 maxChunk = 0;

    for (int i = 0; i < 1024; i++) {
        {
            int chunkIndex = qrand() % 1024;

            qint64 chunkStart = chunkIndex * chunkLength;
            maxChunk = qMax(chunkStart, maxChunk);

            quint8 *ptr;
            ptr = memory.getWriteChunkPtr(KisChunkData(chunkStart, chunkLength));
            memcpy(ptr, writeBuffer.data(), chunkLength);

            dbgKrita << "Writing chunk at" << chunkStart / chunkLength << "MiB" << "max" << maxChunk / chunkLength;
            QTest::qWait(250);
        }

        {
            int chunkIndex = qrand() % 1024;

            qint64 chunkStart = chunkIndex * chunkLength;

            quint8 *ptr;
            ptr = memory.getReadChunkPtr(KisChunkData(chunkStart, chunkLength));
            memcpy(readBuffer.data(), ptr, chunkLength);

            dbgKrita << "Reading chunk at" << chunkStart / chunkLength << "MiB" << "max" << maxChunk / chunkLength;
            QTest::qWait(250);
        }
    }
}
예제 #2
0
bool KisChunkAllocator::tryInsertChunk(KisChunkDataList &list,
                                       KisChunkDataListIterator &iterator,
                                       quint64 size)
{
    bool result = false;
    quint64 highBound = m_storeSize;
    quint64 lowBound = 0;
    quint64 shift = 0;

    if(HAS_NEXT(list, iterator))
        highBound = PEEK_NEXT(iterator).m_begin;

    if(HAS_PREVIOUS(list, iterator)) {
        lowBound = PEEK_PREVIOUS(iterator).m_end;
        shift = 1;
    }

    if(GAP_SIZE(lowBound, highBound) >= size) {
        list.insert(iterator, KisChunkData(lowBound + shift, size));
        result = true;
    }

    return result;
}