- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- PostgreSQL/開発/include/utils/memutils.h へ行く。
- 概要
- 定義
- マクロ
- 列挙型
- 構造体
- 関数
- MemoryContextInit
- MemoryContextReset
- MemoryContextDelete
- MemoryContextResetOnly
- MemoryContextResetChildren
- MemoryContextDeleteChildren
- MemoryContextSetParent
- GetMemoryChunkSpace
- GetMemoryChunkContext
- MemoryContextGetParent
- MemoryContextIsEmpty
- MemoryContextStats
- MemoryContextAllowInCriticalSection
- MemoryContextCheck
- MemoryContextContains
- MemoryContextCreate
- AllocSetContextCreate
- サンプルプログラム
- 参考・関連
- コメント
概要 †
- 概要説明
定義 †
マクロ †
MaxAllocSize, MaxAllocHugeSize †
マクロ名 | 説明 | 値 |
---|---|---|
MaxAllocSize | 0 | |
MaxAllocHugeSize | (8 * 1024 * 1024) |
AllocSizeIsValid, AllocHugeSizeIsValid †
STANDARDCHUNKHEADERSIZE †
MemoryContextResetAndDeleteChildren †
ALLOCSET_DEFAULT_XXXX †
定数 | 説明 | 値 |
---|---|---|
ALLOCSET_DEFAULT_MINSIZE | 0 | |
ALLOCSET_DEFAULT_INITSIZE | (8 * 1024) | |
ALLOCSET_DEFAULT_MAXSIZE | (8 * 1024 * 1024) |
ALLOCSET_SMALL_XXXX †
定数 | 説明 | 値 |
---|---|---|
ALLOCSET_SMALL_MINSIZE | 0 | |
ALLOCSET_SMALL_INITSIZE | (1 * 1024) | |
ALLOCSET_SMALL_MAXSIZE | (8 * 1024) |
ALLOCSET_SEPARATE_THRESHOLD †
列挙型 †
構造体 †
Struct †
番号 | データ型 | フィールド | 説明 |
---|
関数 †
MemoryContextInit †
#define AllocSizeIsValid(size) ((Size) (size) <= MaxAllocSize) #define AllocHugeSizeIsValid(size) ((Size) (size) <= MaxAllocHugeSize)
- メモリコンテスト管理システムの初期化を行なう。
- postmasterのスタートアップ時に呼ばれるので,拡張機能などでこの関数を呼ぶケースはない(すでにメモリコンテキスト管理が利用できる状態になっているため)。
- この処理の中で,TopMemoryContextというメモリコンテキストツリーのトープレベルのメモリコンテキストとErrorContextが作成される。
参考 MemoryContextInit() - on doxygen.postgresql.org
MemoryContextReset †
#define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader))
- 指定されたメモリコンテキスト及び子階層に割り当てられたメモリ領域を解放する。
- 子階層のメモリコンテキストに対しては,MemoryContextDelete()(AllocSetDelete())を再帰的に呼ぶ。
- 対象のメモリコンテキスト(context)については,MemoryContextResetOnly()(AllocSetReset())が呼ばれる。contextの最初のブロック(存在すれば)は残され,メモリチャンクは消去される(freeptrは先頭にポイントされる)。
参考
- AllocSetDelete() - on doxygen.postgresql.org
- AllocSetReset() - on doxygen.postgresql.org
MemoryContextDelete †
#define MemoryContextResetAndDeleteChildren(ctx) MemoryContextReset(ctx)
- 指定されたメモリコンテキストのメモリ領域を解放する。
- 子階層のメモリコンテキストも再帰的に処理される。
参考 MemoryContextDelete() - on doxygen.postgresql.org
MemoryContextResetOnly †
MemoryContext context = AllocSetContextCreate(CurrentMemoryContext, "my context", ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE);
- 指定されたメモリコンテキストをリセットする(AllocSetReset()が呼ばれる)。
- 子階層のメモリコンテキストに対しては何もしない。
MemoryContextResetChildren †
#define ALLOCSET_SEPARATE_THRESHOLD 8192
- 指定されたメモリコンテキストの子階層のメモリコンテキストに対して,再帰的にMemoryContextResetOnly関数を呼ぶ。
MemoryContextDeleteChildren †
extern void MemoryContextInit(void);
- 指定されたメモリコンテキストの子階層のメモリコンテキストに対して,再帰的にMemoryContextDelete関数を呼ぶ。
MemoryContextSetParent †
// 引数1:対象のメモリコンテキスト extern void MemoryContextReset(MemoryContext context);
- 説明
GetMemoryChunkSpace †
// 引数1:対象のメモリコンテキスト extern void MemoryContextDelete(MemoryContext context);
- 説明
GetMemoryChunkContext †
// 引数1:対象のメモリコンテキスト extern void MemoryContextResetOnly(MemoryContext context);
- 説明
MemoryContextGetParent †
// 引数1:対象のメモリコンテキスト extern void MemoryContextResetChildren(MemoryContext context);
- 説明
MemoryContextIsEmpty †
// 引数1:対象のメモリコンテキスト extern void MemoryContextDeleteChildren(MemoryContext context);
- 説明
MemoryContextStats †
#define BLOCK_SIZE 1024 * 8 void reset_callback(void *arg) { MemoryContext context = (MemoryContext)arg; elog(NOTICE, "%s will be deleted.", context->name); } void sample() { MemoryContext oldcontext = NULL; MemoryContextCallback callback; MemoryContextCallback callback2; // init parent context MemoryContext parent_context = AllocSetContextCreate(CurrentMemoryContext, "parent context", 0, BLOCK_SIZE, BLOCK_SIZE); callback.func = reset_callback; callback.arg = parent_context; MemoryContextRegisterResetCallback(parent_context, &callback); oldcontext = MemoryContextSwitchTo(parent_context); // parent context from here StringInfo strinfo = makeStringInfo(); appendStringInfo(strinfo, "Hello %s", "Duke"); elog(NOTICE, "%s", strinfo->data); // init child context MemoryContext child_context = AllocSetContextCreate(parent_context, "child context", 0, BLOCK_SIZE, BLOCK_SIZE); callback2.func = reset_callback; callback2.arg = child_context; MemoryContextRegisterResetCallback(child_context, &callback2); MemoryContextSwitchTo(child_context); // child context from here StringInfo strinfo2 = makeStringInfo(); appendStringInfo(strinfo2, "Hello %s", "Togo"); elog(NOTICE, "%s", strinfo2->data); // switch back to original context. MemoryContextSwitchTo(oldcontext); // delete parent_context and child_context // // CurrentMemoryContext // |- parent_context <--- delete // |- child_context <--- delete MemoryContextDeleteChildren(CurrentMemoryContext); }
- 説明
MemoryContextAllowInCriticalSection †
// 引数1:対象のメモリコンテキスト // 引数2:新しい親となるメモリコンテキスト extern void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent); /* Change a context to belong a new parent. == Before == new_parent current_parent |- context1 |- context <-- move to (o) |- context2 |- next_context == After == new_parent current_parent |- context (o) |- next_context |- context1 |- context2 */
- 説明
MemoryContextCheck †
// 引数1:メモリチャンクのポインタ // 戻り値:メモリチャンクサイズ(ヘッダ含む) extern Size GetMemoryChunkSpace(void *pointer);
- 説明
MemoryContextContains †
void test_chunk_space() { elog(NOTICE, "STANDARDCHUNKHEADERSIZE = %d", STANDARDCHUNKHEADERSIZE); char *chunk1 = palloc(128); // 128 + STANDARDCHUNKHEADERSIZE elog(NOTICE, "%d", GetMemoryChunkSpace(chunk1)); // NOTICE: 152 char *chunk2 = palloc(256-32); // 256 + STANDARDCHUNKHEADERSIZE elog(NOTICE, "%d", GetMemoryChunkSpace(chunk2)); // NOTICE: 280 }
- 説明
MemoryContextCreate †
// 引数1:メモリチャンクのポインタ // 戻り値:メモリチャンクが属するメモリコンテキスト extern MemoryContext GetMemoryChunkContext(void *pointer);
- 説明
AllocSetContextCreate †
void test_chunk() { MemoryContext context = AllocSetContextCreate(CurrentMemoryContext, "my context", 0, 1024 * 8, 1024 * 8); MemoryContext oldcontext = MemoryContextSwitchTo(context); StringInfo strinfo = makeStringInfo(); elog(NOTICE, "%s", GetMemoryChunkContext(strinfo)->name); // NOTICE: my contex MemoryContextSwitchTo(oldcontext); MemoryContextDelete(context); }
サンプルプログラム †
// 引数1:対象のメモリコンテキスト // 戻り値:contextの親のメモリコンテスト extern MemoryContext MemoryContextGetParent(MemoryContext context);
参考・関連 †
関連