JP3582756B2 - Memory management method - Google Patents

Memory management method Download PDF

Info

Publication number
JP3582756B2
JP3582756B2 JP27074996A JP27074996A JP3582756B2 JP 3582756 B2 JP3582756 B2 JP 3582756B2 JP 27074996 A JP27074996 A JP 27074996A JP 27074996 A JP27074996 A JP 27074996A JP 3582756 B2 JP3582756 B2 JP 3582756B2
Authority
JP
Japan
Prior art keywords
handle
character string
memory management
memory
interpreter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
JP27074996A
Other languages
Japanese (ja)
Other versions
JPH10116199A (en
Inventor
育生 依田
哲明 後藤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nippon Telegraph and Telephone Corp
Original Assignee
Nippon Telegraph and Telephone Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nippon Telegraph and Telephone Corp filed Critical Nippon Telegraph and Telephone Corp
Priority to JP27074996A priority Critical patent/JP3582756B2/en
Publication of JPH10116199A publication Critical patent/JPH10116199A/en
Application granted granted Critical
Publication of JP3582756B2 publication Critical patent/JP3582756B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Description

【0001】
【発明の属する技術分野】
本発明は、インタプリタ言語によるプログラムの製作作業時のメモリ管理方法に関するものである。
【0002】
【従来の技術】
文字列処埋を行うインタプリタ言語では、あらゆるデータを文字列で表している。このような言語でオブジェクトを取り扱う場合、オブジェクトへの参照を何らかの文字列(以下、ハンドルと称す。)で表す。通常、オブジェクト参照に当ってはメモリの割り当て、解放が必要である。こうしたメモリ管理の必要なプログラムを製作する時、プログラム製作者はオブジェクトが参照されているかどうか、即ちハンドルが再び使用される可能性があるかどうかを常に意識し、参照されなくなった時点でオブジェクトのメモリを開放する操作をプログラムに組み込んでいた。
【0003】
【発明が解決しようとする課題】
前述したように、メモリ管埋の必要なオブジェクトを用いてプログラムを製作する時、プログラム製作者はオブジェクトが参照されているかどうかを常に正しく意識する必要がある。なぜなら、参照されているオブジェクトのメモリを開放してしまうと、開放されたメモリに対するアクセスが発生し、また、既に参照されなくなったオブジェクトのメモリを開放しないでおくとメモリを浪費し、メモリの不足が発生し、このようなメモリ管理の誤りは深刻なプログラムエラーを引き起こしてしまうからである。
【0004】
インタプリタ言語では、実行時に変数の内容が監視できるため、オブジェクトが参照されているかどうかをプログラム製作者に代わってプログラムを解釈実行するインタプリタが監視することができる。しかしながら、文字列処理を行うこれまでのインタプリタ言語では、文字列の中に埋め込まれたオブジェクトを指し示す部分(ハンドル)についてまでは監視しないため、ハンドルによるオブジェクトのメモリ管埋はプログラム製作者が行うことになり、プログラム製作の作業効率が悪いという問題があった。
【0005】
本発明の目的は、主として文字列処埋を行うインタプリタ言語においても、プログラム製作者によるメモリ管理を必要としないメモリ管理方法を提供することにある。
【0006】
【課題を解決するための手段】
前記課題を解決するため、本発明では、インタプリタで使用される多数の文字から使用頻度の低い文字を選び、該文字の並びで構成した識別記号を含む文字列(ハンドル)によって、インタプリタからメモリ管理の必要なオブジェクトへの参照を表し、ハンドルに対応したインタプリタ言語上のデータ構造(ハンドル構造体)を定義するとともに、ハンドルへの参照回数をハンドル構造体上のデータとして定義し、インタプリタ言語の変数が変更されることによってオブジェクトの参照状態が変更される度に、該オブジェクトに対応するハンドル構造体における参照回数を増減し、その参照回数を監視することによってメモリ管理を行うことにより、ハンドルによるオブジェクトの参照状況をインタプリタが監視できるようにし、誤りのないメモリの割り当て、解放をインタプリタ側で管理可能とする。
【0007】
また、オブジェクトを指すポインタをハンドル構造体上のデータとして定義するとともに、ハンドル構造体の配列またはリストを用意し、ハンドルの文字列をキーとしたインデックス及びオブジェクトを指すポインタ値をキーとしたインデックスを用意することにより、高速な処理を可能とする。
【0008】
【発明の実施の形態】
オブジェクトへの参照を表すハンドルを、通常は現れないような特別な文字の並びで構成した識別記号で始まるようにし、その後ろにハンドル毎に異なる文字列を付けて構成する、例えば”&#%$000123”のような文字列を構成する。ここで”&#%$”は識別記号であり、通常の文章では使用頻度の低い文字、例えば、〜,!,@,#,$,%,^,&等から選択した文字を複数並べて、通常の文章で使われる可能性が非常に低い文字列を用いる。また、”000123”はハンドル毎に異なる文字列である。インタプリタは、変数中の文字列から前記識別記号を検索することにより、ハンドルを捜し出すことができる。
【0009】
オブジェクトのメモリの開放を行う必要があるのは、そのオブジェクトがどこからも参照されなくなった場合である。参照されているかどうかは、実行中のプログラムのデータ領域のどこかにハンドルが存在するかどうかで判断できる。
【0010】
図1は本発明の実施の形態の一例を示すもので、以下のようなデータ構成を有している。
【0011】
1.ハンドルを管理するものとして、以下に示すような内容を含む構造体(以下、ハンドル構造体と称す。)を用意する。
・オブジェクトを指すポインタ
・オブジェクトのメモリを開放する必要があるかどうかのフラグ
・ハンドルの参照数
2.ハンドル構造体の配列またはリスト等を用意する。ハンドルの文字列から、この配列またはリスト等の要素が直ちに分かるようにしておく。例えば、ハンドルの文字列をキーとしたインデックスを作り、対応するハンドルリストの要素が直ちに得られるようにする。
【0012】
3.ハンドル構造体は、オブジェクトを指すポインタ値からできるだけ高速に見つけ出せるようにしておく。例えば、ポインタ値をキーとしたインデックスを用いる。
【0013】
次に、本発明方法の動作を説明する。
【0014】
1.ハンドルが必要になった時(インタプリタにおいて、データ処理中にオブジェクト参照のイベントが発生した時)は、オブジェクトを指すポインタをキーにしてハンドル構造体を探す。既にハンドル構造体があれば、その構造体のハンドルを使う。ハンドルがまだ存在しない場合には、新たにハンドル構造体の要素を作るか、使用されていないハンドル構造体を捜し出し、そこに情報を設定する。ハンドルが指すオブジェクトが後でメモリを開放しなければならないものであれば、そのフラグをセットする。ハンドルの参照数は0にする。
【0015】
2.インタプリタのオブジェクト参照に関わる変数を変更する際に、以下の処理を行う。
【0016】
・変数に以前に設定されていた文字列を捜査し、ハンドルの識別記号を探す。見つかった各ハンドルは、この変更によって参照がなくなるので、ハンドル構造体の参照数を1減らす。例えば、代入操作によって変数Aが変数Bに置き換えられた場合を考えると、変数Aに関わるハンドルの参照数を減らすことになる。
【0017】
・変数に新たに設定する文字列を捜査し、ハンドルの識別記号を探す。見つかった各ハンドルは、この変更によって参照が増えるので、ハンドル構造体の参照数を1増やす。例えば、代入操作によって変数Aが変数Bに置き換えられた場合を考えると、変数Bに関わるハンドルの参照数を増やすことになる。
【0018】
3.オブジェクトのメモリを開放する必要がなくなった場合(例えば、データ処理中に内部でオブジェクトのメモリを開放するサブルーチンにオブジェクトを渡した場合)には、ハンドル構造体のメモリ開放の必要性を示すフラグを寝かす。逆に、再びオブジェクトのメモリを開放する必要が発生した場合(例えば、データ処埋中にオブジェクトのメモリ管理権を譲り受けるサブルーチンを呼出した場合)には、ハンドル構造体のメモリ開放の必要性を示すフラグを立てる。
【0019】
4.何らかの理由でオブジェクトのメモリが開放されてしまった場合(例えば、データ処理中に内部でオブジェクトのメモリを開放するサブルーチンがオブジェクトのメモリを開放した場合)には、ハンドル構造体の要素も削除する。
【0020】
5.インタプリタは何らかのタイミングでハンドル構造体の各要素を捜査し、参照数が0になっているハンドル構造体を削除する。この時、オブジェクトのメモリの開放が必要であれば開放する。
【0021】
図2に本発明方法の動作フローチャートを示す。この図では、上記3、4の処理は省略している。また、5の処理を行うタイミングを変数の変更時として記述している。5の処埋はインタプリタ起動後のいずれの時点で行っても良いが、
(1)2.の処理の終了後、(2)プログラムの待状態にある時、(3)別途定めたハンドル数の上限もしくは割り付けられているメモリの上限になった時、等が有効である。(1)は最も細かく監視する方法であり、(2)はインタプリタに負担をかけない方法、(3)は(1)と(2)の中間であり、監視の必要性を受けて動作する。
【0022】
ここで、前記識別記号と同じ文字列が、たまたま通常の文字列としてデータの文字列中に含まれる可能性もあるが、対応するハンドル構造体がなければハンドルとして認識しないようにすれば問題ない。これは文字列中の識別記号以外の部分が異なれば、それはハンドル構造体の識別記号でなく、通常のデータ上の文字列として扱うことによって容易に可能である。
【0023】
また、使用中のハンドルと全く同じ文字列が通常の文字列として使われていると、その文字列が変数中に存在する間、ハンドル構造体の参照数が本来の参照数より多く設定され、本来の参照数が0になってもオブジェクトのメモリが開放されない。しかし、通常の文字列として使われているハンドルと全く同じ文字列が変数からなくなった時点でメモリは開放されるため、実用上問題はない。ハンドルと全く同じ文字列が大量にしかも永久にデータ中に存在する場合に限り、メモリの浪費の問題が発生するが、前述したように、もともとハンドル用の文字列として使用頻度の低い文字を選定しており、ハンドルと全く同じ文字列が大量に続くことは有り得ないと考えて良い。
【0024】
【実施例】
文字列処理を行うインタプリタ言語としてTclを使用し、メモリ管埋が必要なオブジェクトとしてC++言語のインスタンスを使用した場合についての実施例を示す。
【0025】
Tclはアプリケーション独立の拡張可能なコマンド解釈部ライブラリである。Tclの参考文献としては、“Tcl and the Tk Toolkit”John O.Ousterhout ,Addison−Wesley,1994、がある。
【0026】
本実施例は、C++言語で製作されたプログラムに、Tclによるアプリケーションプログラムインタフェース(API)を追加した場合に相当する。このようなAPIには、Tclのようなインタプリタ言語の持つ、コンパイルが不用で即実行可能であるという利点と、C++言語のように高速に動作するコンパイル言語の利点を合わせて用いることができるという特徴がある。
【0027】
このようなAPIでは、Tclにコマンドを追加し、そのコマンドの中でC++のプログラムを呼び出す。呼び出されたC++のプログラムが何らかのC++インスタンスをTcl側に返す場合、Tclではデータが全て文字列であるため、C++インスタンスからそれを指し示すハンドルを生成し、これを返す。追加したTclのコマンドに対して、Tcl側から以前に得たC++インスタンスを渡す場合にはそのハンドルを渡す。コマンドから呼び出されたC++プログラムは、ハンドルからC++インスタンスへのポインタを得て、C++インスタンスに対する処理を実施する。
【0028】
Tclでは、データは全て文字列であり、その文字列は変数から参照されている。データを表す全変数から参照されている文字列の中に、あるC++のインスタンスを指すハンドルがどこにも存在しなければ、そのC++インスタンスは二度と参照されないので、deleteしてかまわないことになる。なお、deleteとはC++言語におけるメモリ開放指示である。
【0029】
そこで、Tclの変数に文字列を入れる際に、文字列中のハンドルの存在の有無を調べ、ハンドルの存在状態を完全に把握すれば、API側でメモリ管理を行うことができ、APIを使うプログラム製作者はメモリ管埋をしなくて済む。
【0030】
以下に、その方法の具体的な手順の例を示す。
【0031】
1.ハンドルを管理するものとして、以下に示すような内容を含む構造体(以下、ハンドル構造体と称す。)を用意する。
・C++のインスタンスを指すポインタ
・C++のインスタンスのクラス
・C++のインスタンスをdeleteする必要があるかどうかのフラグ
・ハンドルの参照数
・ハンドル構造体が使われているかどうかのフラグ
2.十分な大きさのハンドル構造体の配列を用意する。ハンドルの名前はこの配列の要素番号から作るようにする。逆に言えば、ハンドルの名前から、ハンドル構造体の配列の要素番号が分かるようにしておく。例えば、ハンドルが”&#%$000003”なら、このハンドルに対応するハンドル構造体は”xxxx[3]”で得られるようにする。
【0032】
3.ハンドル構造体の各要素は、C++のインスタンスを指すポインタをキーにしたハッシュテーブルを製作してこれに登録しておく。つまり、ポインタ値からできるだけ高速にハンドル構造体を見つけ出せるようにしておく。ハッシュテーブルとは、ある大きさのテーブルを用意し、各要素をこのテーブル内にできるだけ均等に振り分けるため、キーをハッシュ関数によりテーブルの大きさの範囲の数値に変換し、テーブル中のこの数値の位置に要素を格納するものである。検索時にはキーをハッシュ関数により数値に変換し、テーブル中のこの数値の位置から要素を探すことにより、高速に検索できる。
【0033】
4.APIとしてTclに追加されたコマンドからハンドルを返す場合等、ハンドルが必要になった時は、C++のインスタンスを指すポインタをキーにしてハッシュテーブルからハンドル構造体の要素を探す。既にハンドル構造体の要素があれば、その要素の配列の要素番号からハンドル名を作って返す。ハンドルがまだ存在しない場合には、使用されていないハンドル構造体の要素を捜し出し、そこに情報を設定する。ハンドルが指すC++のインスタンスが、後でdeleteしなければならないものであれば、そのフラグをセットする。ハンドルの参照数は0にする。
【0034】
5.Tclにおいて、変数への代入を実施している部分を以下のように改造する。
【0035】
・変数に以前に設定されていた文字列を捜査して、この文字列から参照されていた各ハンドルを探す。各ハンドルは、この代入によって参照がなくなるので、ハンドルの参照数を1減らす。
【0036】
・変数に新たに代入される文字列を捜査して、この文字列から参照されている各ハンドルを探す。各ハンドルは、この代入によって参照が増えるので、ハンドルの参照数を1増やす。
【0037】
・代入終了後、この代入によって参照数が変化したハンドルの中で参照数が0になったものがあれば、そのハンドルのハンドル構造体を未使用に設定し、ハッシュテーブルから除き、C++インスタンスのdeleteが必要であればdeleteを実施する。
【0038】
6.Tclにおいて、変数を無効にしている部分(例えば、returnによりプロシージャのローカル変数を破棄している部分)を改造して、参照されなくなるハンドルの参照数を減らす処埋をいれる。変数の無効化よって参照数が0になったハンドルがあれば、そのハンドルのハンドル構造体を未使用に設定し、ハッシュテーブルから除き、C++インスタンスのdeleteが必要であればdeleteを実施する。
【0039】
7.ハンドルがAPIとしてTclに追加されたコマンドを通じてC++インスタンスへのポインタに戻され、C++の関数に渡され、その関数内でメモリ管理がC++プログラム側に移った場合には、ハンドル構造体のdeleteの必要性のフラグを寝かす。
【0040】
8.C++インスタンスのデストラクタを改造し、C++インスタンスがC++プログラム側でdeleteされた場合には、そのC++インスタンスを指すハンドル構造体を探してC++インスタンスへのポインタをNULLに設定する。同時に、ハンドル構造体をC++インスタンスへのポインタをキーとしたハッシュテーブルから除く。
【0041】
未使用のハンドル構造体、参照数が0のハンドル構造体をそれぞれ専用のリストに繋いで管理することにより、さらに高速に処理を行うことができる。
【0042】
【発明の効果】
以上説明したように、本発明によれば、文字列処理を行うインタプリタ言語においても、メモリ管理を行うことなく、効率的なプログラム製作を行うことができるとともに、メモリ管理の誤りによる深刻なプログラムエラーを完全に排除することができる。
【図面の簡単な説明】
【図1】本発明の実施の形態の一例を示すデータ構成図
【図2】本発明方法の動作フローチャート
[0001]
TECHNICAL FIELD OF THE INVENTION
The present invention relates to a memory management method when a program is created in an interpreted language.
[0002]
[Prior art]
In an interpreter language that performs character string processing, all data is represented by character strings. When handling an object in such a language, a reference to the object is represented by a character string (hereinafter, referred to as a handle). Usually, memory allocation and deallocation is required for object reference. When creating a program that requires such memory management, the program creator is always aware of whether the object is being referenced, that is, whether the handle may be used again. The operation to release the memory was incorporated in the program.
[0003]
[Problems to be solved by the invention]
As described above, when producing a program using objects that require memory management, the program creator must always correctly recognize whether or not the objects are referenced. This is because if the memory of the referenced object is released, access to the released memory occurs, and if the memory of the object that is no longer referenced is not released, the memory is wasted and the memory becomes insufficient. Occurs, and such a memory management error causes a serious program error.
[0004]
In the interpreted language, since the contents of variables can be monitored at the time of execution, an interpreter that interprets and executes a program on behalf of a program creator can monitor whether or not an object is referenced. However, in the conventional interpreter language that performs character string processing, the part (handle) indicating the object embedded in the character string is not monitored, so the memory of the object using the handle must be stored by the program creator. And there is a problem that the work efficiency of the program production is poor.
[0005]
An object of the present invention is to provide a memory management method that does not require memory management by a program creator even in an interpreted language that mainly performs character string processing.
[0006]
[Means for Solving the Problems]
In order to solve the above-mentioned problem, the present invention selects a character that is used less frequently from a large number of characters used in the interpreter, and uses a character string (handle) including an identification symbol composed of a sequence of the characters to execute memory management from the interpreter. Represents a reference to an object that requires a handle, defines a data structure in the interpreter language corresponding to the handle (handle structure), defines the number of references to the handle as data in the handle structure, and interprets the variables in the interpreter language. Every time the reference state of an object is changed by changing the object, the number of references in the handle structure corresponding to the object is increased or decreased, and the memory management is performed by monitoring the number of references. To allow the interpreter to monitor the reference status of Assigning Mori, and can be managed by releasing the interpreter side.
[0007]
In addition, a pointer to the object is defined as data on the handle structure, and an array or list of the handle structure is prepared, and the index using the character string of the handle as a key and the index using the pointer value indicating the object as a key are used. The preparation enables high-speed processing.
[0008]
BEST MODE FOR CARRYING OUT THE INVENTION
A handle that represents a reference to an object starts with a special character sequence that does not normally appear, followed by a different character string for each handle. For example, "&#% A character string such as $ 000123 "is formed. Here, “&#% $” is an identification symbol, and characters that are not frequently used in ordinary sentences, for example, ~ ,! , @, #, $,%, ^, & etc., a plurality of characters selected are arranged, and a character string that is very unlikely to be used in ordinary sentences is used. “000123” is a character string that differs for each handle. The interpreter can find the handle by searching the character string in the variable for the identification symbol.
[0009]
It is necessary to release the memory of an object when the object is no longer referenced from anywhere. Whether it is referenced can be determined by whether a handle exists somewhere in the data area of the running program.
[0010]
FIG. 1 shows an example of an embodiment of the present invention, and has the following data configuration.
[0011]
1. A structure including the following contents (hereinafter, referred to as a handle structure) is prepared for managing the handle.
1. Pointer pointing to the object. Flag indicating whether the memory of the object needs to be released. Prepare an array or list of handle structures. The element of this array or list should be immediately known from the string of the handle. For example, an index is formed using a handle string as a key so that the corresponding handle list element can be obtained immediately.
[0012]
3. The handle structure should be found as fast as possible from the pointer value pointing to the object. For example, an index using a pointer value as a key is used.
[0013]
Next, the operation of the method of the present invention will be described.
[0014]
1. When a handle is needed (when an event of referring to an object occurs during data processing in the interpreter), a handle structure is searched using a pointer to the object as a key. If there is already a handle structure, use the handle of that structure. If the handle does not yet exist, a new handle structure element is created or an unused handle structure is searched for and information is set there. If the object pointed to by the handle needs to free memory later, set its flag. The reference number of the handle is set to 0.
[0015]
2. The following processing is performed when changing variables related to the object reference of the interpreter.
[0016]
Search for the character string previously set in the variable and look for the handle identification symbol. Since each handle found has no reference due to this change, the number of references in the handle structure is reduced by one. For example, considering the case where the variable A is replaced by the variable B by the assignment operation, the number of references to the handle related to the variable A is reduced.
[0017]
-Search for a character string to be newly set in the variable, and search for the identification symbol of the handle. Since the reference of each found handle is increased by this change, the reference number of the handle structure is increased by one. For example, considering the case where the variable A is replaced by the variable B by the assignment operation, the reference number of the handle related to the variable B is increased.
[0018]
3. When it is no longer necessary to release the memory of the object (for example, when the object is passed to a subroutine that releases the memory of the object internally during data processing), a flag indicating the need to release the memory of the handle structure is set. I lie down. Conversely, when it is necessary to release the memory of the object again (for example, when a subroutine for assigning the memory management right of the object is called during data processing), it indicates the need to release the memory of the handle structure. Set the flag.
[0019]
4. If the memory of the object is released for some reason (for example, if a subroutine that releases the memory of the object internally during data processing releases the memory of the object), the element of the handle structure is also deleted.
[0020]
5. The interpreter searches each element of the handle structure at some timing, and deletes the handle structure whose reference number is 0. At this time, the memory of the object is released if necessary.
[0021]
FIG. 2 shows an operation flowchart of the method of the present invention. In this figure, the above processes 3 and 4 are omitted. Also, the timing of performing the process 5 is described as when the variable is changed. The processing of 5 may be performed at any time after the start of the interpreter,
(1) 2. (2) When the program is in a waiting state, (3) When the upper limit of the number of handles or the upper limit of the allocated memory is reached. (1) is a method of monitoring the most minutely, (2) is a method that does not burden the interpreter, and (3) is an intermediate between (1) and (2) and operates in response to the need for monitoring.
[0022]
Here, there is a possibility that the same character string as the identification symbol is accidentally included in the data character string as a normal character string, but there is no problem if it is not recognized as a handle if there is no corresponding handle structure. . This can be easily achieved by treating a portion other than the identification symbol in the character string as a character string on ordinary data, instead of the identification symbol of the handle structure.
[0023]
Also, if the same string as the handle in use is used as a normal string, the reference number of the handle structure is set to be larger than the original reference number while the string exists in the variable, Even if the original reference number becomes 0, the memory of the object is not released. However, there is no practical problem since the memory is released when the character string exactly the same as the handle used as the normal character string is no longer stored in the variable. The problem of wasting memory occurs only when a large number of character strings identical to the handle are permanently present in the data. However, as described above, originally used characters that are rarely used are selected as the string for the handle. It can be considered that it is unlikely that the same character string as the handle continues in large quantities.
[0024]
【Example】
An embodiment will be described in which Tcl is used as an interpreter language for performing character string processing, and an instance of the C ++ language is used as an object requiring memory management.
[0025]
Tcl is an application-independent and extensible command interpreter library. References to Tcl include "Tcl and the Tk Toolkit", John O. Osterhout, Addison-Wesley, 1994.
[0026]
This embodiment corresponds to a case where an application program interface (API) using Tcl is added to a program manufactured in the C ++ language. Such an API can combine the advantages of an interpreted language such as Tcl, which requires no compilation and can be executed immediately, and the advantages of a compiled language that operates at high speed, such as the C ++ language. There is a feature.
[0027]
In such an API, a command is added to Tcl, and a C ++ program is called in the command. When the called C ++ program returns some C ++ instance to the Tcl side, since all data is a character string in Tcl, a handle indicating the C ++ instance is generated from the C ++ instance and returned. When the C ++ instance previously obtained from the Tcl side is passed to the added Tcl command, the handle is passed. C ++ program called from the command, with the pointer to the C ++ instance from the handle, carrying out the processing for the C ++ instance.
[0028]
In Tcl, all data is a character string, and the character string is referenced by a variable. If there is no handle pointing to a C ++ instance anywhere in the string referenced by all variables representing data, the C ++ instance will not be referenced again, so it can be deleted. . Note that “delete” is a memory release instruction in the C ++ language.
[0029]
Therefore, when inserting a character string into the variable of Tcl, if the existence of the handle in the character string is checked and the existence state of the handle is completely grasped, memory management can be performed on the API side, and the API is used. Program creators do not have to manage memory.
[0030]
An example of a specific procedure of the method will be described below.
[0031]
1. A structure including the following contents (hereinafter, referred to as a handle structure) is prepared for managing the handle.
· C ++ pointer, C ++ of whether the number of reference handle structure whether an instance of the class-C ++ for instance it is necessary to delete one of the flag handle is used flags 2 to refer to instances of. Prepare an array of handle structures that are large enough. Handle names are created from the element numbers of this array. In other words, the element number of the array of the handle structure is known from the name of the handle. For example, if the handle is “&#% $ 000003”, the handle structure corresponding to this handle is obtained as “xxxx [3]”.
[0032]
3. For each element of the handle structure, a hash table using a pointer pointing to an instance of C ++ as a key is created and registered in the hash table. That is, it is necessary to find the handle structure from the pointer value as quickly as possible. A hash table is a table of a certain size. To distribute each element in this table as evenly as possible, the key is converted to a numerical value within the range of the table size by a hash function, The element is stored at the position. At the time of retrieval, the key can be converted into a numerical value by a hash function, and an element can be searched from the position of the numerical value in the table, thereby performing high-speed retrieval.
[0033]
4. When a handle is needed, such as when a handle is returned from a command added to Tcl as an API, an element of the handle structure is searched from the hash table using a pointer pointing to an instance of C ++ as a key. If an element of the handle structure already exists, a handle name is created and returned from the element number of the array of the element. If the handle does not yet exist, an element of the handle structure that is not used is searched for, and information is set there. If the C ++ instance pointed to by the handle must be deleted later, set its flag. The reference number of the handle is set to 0.
[0034]
5. In Tcl, the part where the substitution into the variable is performed is modified as follows.
[0035]
Search the character string previously set in the variable to find each handle referenced from this character string. Since each handle has no reference due to this assignment, the number of references to the handle is reduced by one.
[0036]
Search for a character string newly assigned to a variable, and search for each handle referenced from this character string. Since the reference of each handle is increased by this substitution, the reference number of the handle is increased by one.
[0037]
After the assignment is completed, if any of the handles whose reference number has changed by this assignment has a reference number of 0, the handle structure of the handle is set to unused, removed from the hash table, and the C ++ instance is executed. If necessary, delete is performed.
[0038]
6. In Tcl, a part that invalidates a variable (for example, a part in which a local variable of a procedure is discarded by return) is remodeled, and processing for reducing the number of references of a handle that is no longer referred to is included. If there is a handle whose reference number has become 0 due to the invalidation of the variable, the handle structure of the handle is set to unused, and the handle structure is removed from the hash table, and if the C ++ instance needs to be deleted, the delete is executed.
[0039]
7. Handle is returned to the pointer to the C ++ instance through commands added to Tcl as API, it is passed to a function of C ++, if the memory management is shifted to C ++ program side within the function, a handle structure Lose flag of need for delete.
[0040]
8. Remodeled destructor of C ++ instance, if the C ++ instance is delete a C ++ program side, sets the pointer to the handle structure Seeking C ++ instance that points to the C ++ instance to NULL. At the same time, the handle structure is removed from the hash table using the pointer to the C ++ instance as a key.
[0041]
By managing the unused handle structure and the handle structure having a reference number of 0 by respectively connecting them to a dedicated list, processing can be performed at higher speed.
[0042]
【The invention's effect】
As described above, according to the present invention, even in an interpreted language that performs character string processing, efficient program production can be performed without performing memory management, and serious program errors due to erroneous memory management can be achieved. Can be completely eliminated.
[Brief description of the drawings]
FIG. 1 is a data configuration diagram showing an example of an embodiment of the present invention. FIG. 2 is an operation flowchart of a method of the present invention.

Claims (2)

文字列処理を行うインタプリタ言語によってオブジェクトのメモリを管理するメモリ管理方法において、
インタプリタで使用される多数の文字から使用頻度の低い文字を選び、該文字の並びで構成した識別記号を含む文字列(ハンドル)によって、インタプリタからメモリ管理の必要なオブジェクトへの参照を表し、
ハンドルに対応したインタプリタ言語上のデータ構造(ハンドル構造体)を定義するとともに、ハンドルへの参照回数をハンドル構造体上のデータとして定義し、
インタプリタ言語の変数が変更されることによってオブジェクトの参照状態が変更される度に、該オブジェクトに対応するハンドル構造体における参照回数を増減し、その参照回数を監視することによってメモリ管理を行う
ことを特徴とするメモリ管理方法。
In a memory management method for managing an object memory using an interpreter language that performs character string processing,
Infrequently used characters are selected from a large number of characters used in the interpreter, and a character string (handle) including an identification symbol composed of the character sequence represents a reference from the interpreter to an object requiring memory management,
In addition to defining a data structure (handle structure) in the interpreter language corresponding to the handle, the number of references to the handle is defined as data in the handle structure,
Each time the reference state of an object is changed by changing a variable in the interpreter language, the number of references in the handle structure corresponding to the object is increased or decreased, and memory management is performed by monitoring the number of references. Characterized memory management method.
オブジェクトを指すポインタをハンドル構造体上のデータとして定義するとともに、ハンドル構造体の配列またはリストを用意し、ハンドルの文字列をキーとしたインデックス及びオブジェクトを指すポインタ値をキーとしたインデックスを用意することを特徴とする請求項1記載のメモリ管理方法。Define a pointer to the object as data on the handle structure, prepare an array or list of handle structures, and prepare an index using the character string of the handle as a key and an index using the pointer value pointing to the object as a key 2. The memory management method according to claim 1, wherein:
JP27074996A 1996-10-14 1996-10-14 Memory management method Expired - Fee Related JP3582756B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP27074996A JP3582756B2 (en) 1996-10-14 1996-10-14 Memory management method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP27074996A JP3582756B2 (en) 1996-10-14 1996-10-14 Memory management method

Publications (2)

Publication Number Publication Date
JPH10116199A JPH10116199A (en) 1998-05-06
JP3582756B2 true JP3582756B2 (en) 2004-10-27

Family

ID=17490450

Family Applications (1)

Application Number Title Priority Date Filing Date
JP27074996A Expired - Fee Related JP3582756B2 (en) 1996-10-14 1996-10-14 Memory management method

Country Status (1)

Country Link
JP (1) JP3582756B2 (en)

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH06105435B2 (en) * 1985-10-25 1994-12-21 株式会社日立製作所 Storage management mechanism by information processing device
JPS649547A (en) * 1987-07-02 1989-01-12 Mitsubishi Electric Corp Memory management device
JPH07114470A (en) * 1993-10-19 1995-05-02 Nec Corp Shared data managing system

Also Published As

Publication number Publication date
JPH10116199A (en) 1998-05-06

Similar Documents

Publication Publication Date Title
US5437029A (en) Path name resolution method providing fixed speed of file accessing in computer network
KR100243717B1 (en) Method and apparatus for enabling a persistent metastate for objects in an object-oriented environment
US4864497A (en) Method of integrating software application programs using an attributive data model database
US7117502B1 (en) Linked-list implementation of a data structure with concurrent non-blocking insert and remove operations
US6526441B2 (en) Input/output device information management system for multi-computer system
US5664177A (en) Data processing system having a data structure with a single, simple primitive
US6055527A (en) System, method and computer program product for superimposing attributes on hierarchically organized file systems
US5488717A (en) MTree data structure for storage, indexing and retrieval of information
EP0453707A2 (en) Method and means for managing space re-use in a shadow written B-tree via free space lists
EP0474395A2 (en) Data storage hierarchy with shared storage level
JP2769100B2 (en) Parallel tables for data models with inheritance
JPH04297934A (en) Data processing system
JPH03138734A (en) Object directional data base management system
JP2000181917A (en) Structured document managing method, executing device therefor and medium recording processing program therefor
JPH11252209A (en) Network management system
US7007146B2 (en) System and method for relocating pages pinned in a buffer pool of a database system
US7991976B2 (en) Permanent pool memory management method and system
US6421689B1 (en) Moderately conservative, mostly copying 2 space garbage collector in the nursery of a generational memory manager
JPH0696025A (en) System and method for controlling data memory
US6571250B1 (en) Method and system for processing queries in a data processing system using index
CN117271531A (en) Data storage method, system, equipment and medium
JP3582756B2 (en) Memory management method
JP3666907B2 (en) Database file storage management system
US6732261B2 (en) Method and apparatus for implementing a register scan process
US6625614B1 (en) Implementation for efficient access of extended attribute data

Legal Events

Date Code Title Description
TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20040720

RD01 Notification of change of attorney

Free format text: JAPANESE INTERMEDIATE CODE: A7426

Effective date: 20040723

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20040723

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20080806

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20080806

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20090806

Year of fee payment: 5

LAPS Cancellation because of no payment of annual fees