このページでは

C

Qul::Platform::StackAllocator Class

class Qul::Platform::StackAllocator

キャッシュ用に一時的に追加のメモリを必要とする可能性のある関数向けに、シンプルなメモリアロケータを提供します。詳細...

Header: #include <platform/alloc.h>
Since: Qt Quick Ultralite (Platform) 1.5

パブリック型

(since Qt Quick Ultralite (Platform) 1.5) class Allocation

静的パブリックメンバー

int32_t available()

詳細な説明

StackAllocator 要求された量よりも少ないメモリが割り当てられる場合があり、関数はその状況に適切に対処する必要があります。

プラットフォームライブラリは、静的メンバー変数を、StackAllocator 用に確保されたバッファの先頭に初期化する必要があります:

  • m_buffer バッファの先頭。
  • m_top バッファの先頭。この変数は m_buffer に初期化する必要があります。
  • m_size バッファのサイズ(バイト単位)に設定します。

StackAllocator の典型的な初期化:

#include <platform/alloc.h>

static char scratch_buffer[16 * 1024];
char *StackAllocator::m_buffer = scratch_buffer;
char *StackAllocator::m_top = StackAllocator::m_buffer;
int32_t StackAllocator::m_size = sizeof(scratch_buffer);

StackAllocatorの典型的な使用例:

#include <platform/alloc.h>

Qul::Platform::StackAllocator::Allocation alloc(requestedSize);
if (requestedSize == alloc.size()) {
    doStuff(alloc.data());
} else {
    error();
}

alloc がスコープ外になると、デストラクタによってメモリが解放されます。

Qul::Platform::StackAllocator::Allocationも参照してください

メンバ関数のドキュメント

[static] int32_t StackAllocator::available()

割り当て可能なバイト数を返します。

StackAllocator のメンバ変数が初期化されていない場合、この関数は0を返します。

特定のQtライセンスの下で利用可能です。
詳細はこちら。