メモリ管理

Server allocates memory in memory contexts in such way that allocations made in one context may be freed by context destruction without affecting allocations made in other contexts. All allocations (via palloc, etc) are made in the context which are chosen as current one. You'll get unpredictable results if you'll try to free (or reallocate) memory allocated not in current context.

サーバはメモリコンテキスト内でメモリの割り当てを行ないます。ある メモリコンテキストで割り当てられたメモリは、そのコンテキストを破 壊することによって、他のコンテキストで割り当てられたメモリに影響 を与えることなく開放できます。( palloc などによ り)割り当てられたメモリは全て、現在のコンテキストとして選ばれた コンテキスト内に作成されています。現在のコンテキストの外部に割り 当てられたメモリを開放(または、再割り当て)を行なおうとした場合、 予期できない結果を得ることになります。

Creation and switching between memory contexts are subject of SPI manager memory management.

メモリコンテキストの生成と切替えは SPI マネージャのもつメモリ管理 機能によって行なわれます。

SPI procedures deal with two memory contexts: upper Executor memory context and procedure memory context (if connected).

SPI プロシージャは2つのメモリコンテキストを扱います。上位エグゼキュ ータのメモリコンテキストと(接続済みの場合)プロシージャメモリコン テキストです。

Before a procedure is connected to the SPI manager, current memory context is upper Executor context so all allocation made by the procedure itself via palloc/repalloc or by SPI utility functions before connecting to SPI are made in this context.

SPI マネージャにプロシージャが接続されるまでは、現在のメモリコンテキ ストは上位エグゼキュータコンテキストになっています。ですので、プロシ ージャ自体が pallocrepalloc 、または、SPI ユーティリティ関数を使っ て生成する割り当てメモリはこのコンテキストに作成されます。

After SPI_connect is called current context is the procedure's one. All allocations made via palloc/repalloc or by SPI utility functions (except for SPI_copytuple, SPI_modifytuple, SPI_palloc and SPI_repalloc) are made in this context.

SPI_connect が呼び出されると、現在のコンテキス トはプロシージャのコンテキストになります。 pallocrepalloc、または ( SPI_copytupleSPI_modifytupleSPI_pallocSPI_repalloc を除く)SPI ユーティリティ関数を使 って生成した割り当てメモリはこのコンテキストに作成されます。

When a procedure disconnects from the SPI manager (via SPI_finish) the current context is restored to the upper Executor context and all allocations made in the procedure memory context are freed and can't be used any more!

プロシージャが( SPI_finish を使って)SPI マネー ジャーから切断されると、現在のコンテキストは上位エグゼキュータのコンテ キストに戻され、プロシージャメモリコンテキストに作成された割り当てメモ リは開放され、二度と使えなくなります。

If you want to return something to the upper Executor then you have to allocate memory for this in the upper context!

上位エグゼキュータに何かを返したい場合、そのためのメモリを上位コンテ キストに割り当てなければなりません!

SPI has no ability to automatically free allocations in the upper Executor context!

SPI は上位エグゼキュータに割り当てたメモリを自動的に開放する機能を 持ちません!

SPI automatically frees memory allocated during execution of a query when this query is done!

問い合わせが完了すると、SPI は問い合わせ実行中に割り当てたメモリを 自動的に開放します!