JP2016186697A - Method and mechanism for sharing variable among functions - Google Patents
Method and mechanism for sharing variable among functions Download PDFInfo
- Publication number
- JP2016186697A JP2016186697A JP2015066131A JP2015066131A JP2016186697A JP 2016186697 A JP2016186697 A JP 2016186697A JP 2015066131 A JP2015066131 A JP 2015066131A JP 2015066131 A JP2015066131 A JP 2015066131A JP 2016186697 A JP2016186697 A JP 2016186697A
- Authority
- JP
- Japan
- Prior art keywords
- value
- identifier
- variable
- function
- unit
- 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.)
- Pending
Links
Images
Abstract
Description
本発明は、コンピュータプログラムの開発に関し、特に、同一プロセス内の異なる複数の関数の間で変数を共有するための方法及び機構に関する。 The present invention relates to computer program development, and more particularly to a method and mechanism for sharing variables between different functions within the same process.
C言語などによるプログラム開発では、ヘッダーファイルが利用される。一般にはヘッダーファイルには、変数や関数の宣言などが記述されている。ソースファイルの中でヘッダーファイルを読み込むべき位置に、ヘッダーファイルを指定してinclude文あるいはinclude(インクルード)指令(例えば、#include)を記載しておけば、指定されたヘッダーファイルがプリプロセッサによってソースファイル内に読み込まれる。複数のソースファイルで利用される関数の宣言をヘッダーファイルに記述しておけば、各ソースファイルそのそれぞれに関数の宣言を記述する必要がなく、ヘッダーファイルを読み込むだけでよい。また、ライブラリ関数の宣言が記述されたヘッダーファイルを利用すると、ライブラリ関数を利用するソースファイルに関数の宣言を記述する必要がなくなり、ライブラリの利便性が高まるという利点もある。 A header file is used in program development in C language or the like. In general, a header file contains declarations of variables and functions. If the header file is specified in the source file at the position where the header file is to be read and an include statement or include (include) directive (for example, #include) is described, the specified header file is sourced by the preprocessor. Is read in. If function declarations used in multiple source files are described in the header file, it is not necessary to describe the function declarations in each source file, and only the header file is read. Further, when a header file in which a library function declaration is described is used, there is no need to describe the function declaration in a source file that uses the library function, and there is an advantage that the convenience of the library is improved.
一方で、関数の定義自体をヘッダーファイルに記述することも行われる。コンパイラは一般に複数のソースファイルを個別にコンパイルするため、異なるソースファイルで定義された関数間に呼び出し関係があった場合にも、それらの関数間でインライン展開などの最適化を行わない。これに対してヘッダーファイルに関数の定義がある場合には、ヘッダーファイルはプリプロセッサによってソースファイルに読み込まれるため、コンパイラがソースファイルとヘッダーファイルで定義された関数との間での最適化を行うことができるという利点が生じる。このため、利用頻度が高い関数や、関数の大きさが小さい場合(すなわちインライン展開のデメリットが少ない場合)には、ヘッダーファイルにおいて関数定義を行うということがしばしば行われる。本明細書では、ヘッダーファイルで定義された関数を対象とする。 On the other hand, the function definition itself is also described in the header file. Since a compiler generally compiles a plurality of source files individually, even if there is a call relationship between functions defined in different source files, optimization such as inline expansion is not performed between these functions. On the other hand, if there is a function definition in the header file, the header file is read into the source file by the preprocessor, so the compiler should optimize between the source file and the function defined in the header file. The advantage is that For this reason, when a function is frequently used or when the size of the function is small (that is, when the disadvantages of inline expansion are small), function definition is often performed in a header file. In this specification, the function defined in the header file is targeted.
一般に、同一プロセス内の複数の関数間で変数の共有を行う場合は、関数の引数もしくはグローバル変数が用いられる。図1は、関数の引数によって、関数間で変数の共有を行う場合の例を擬似コードによって示している。この例では、関数func1及び関数func2の引数として、int(整数)型変数へのポインタを渡している。関数func1では、ポインタで示されたアドレスに値を書き込み、関数func2では、ポインタで示されたアドレスの値を参照している。このように複数の関数で同一の変数を利用することを、本明細書では変数の共有と呼ぶ。 Generally, when a variable is shared among a plurality of functions in the same process, a function argument or a global variable is used. FIG. 1 shows, in pseudo code, an example in which a variable is shared between functions using function arguments. In this example, pointers to int (integer) type variables are passed as arguments of the functions func1 and func2. The function func1 writes a value to the address indicated by the pointer, and the function func2 refers to the value of the address indicated by the pointer. The use of the same variable in a plurality of functions in this way is referred to as variable sharing in this specification.
引数を用いることで関数間での変数の共有が可能ではあるが、この場合、関数の呼び出し側に、引数を渡してもらう必要がある。共有する変数が、呼び出される関数のみで利用されるものである場合、呼び出し側にとって、本来、この変数は意識する必要のないものである。そのような変数を呼び出し側で管理することは、プログラムを複雑にするという課題を生ずる。なお、C++のようなオブジェクト指向言語では、共有する変数にオブジェクトのメンバ変数を利用すると、オブジェクトのメンバ関数の引数として共有変数を渡す必要はなくなる。しかしながら、メンバ変数を利用する場合であっても、呼び出し側でオブジェクトを管理する必要があり、本質的には同じ課題が生ずる。すなわち、関数間で変数を共有するためだけにオブジェクトを利用することは、本来ならばオブジェクトを管理することは関数の呼び出し側には不要なことであるので、呼び出し側のプログラムを複雑にするという課題を生じる。 Although it is possible to share variables between functions by using arguments, in this case, it is necessary to have the function caller pass the arguments. If the shared variable is used only by the function to be called, this variable is essentially not necessary for the caller. Managing such variables on the caller raises the problem of complicating the program. In an object-oriented language such as C ++, when an object member variable is used as a shared variable, it is not necessary to pass the shared variable as an argument of the object member function. However, even when using member variables, it is necessary to manage objects on the call side, and the same problem arises essentially. In other words, using an object only to share a variable between functions means that managing the object is not necessary for the function caller, which complicates the calling program. Create a challenge.
一方、図2は、グローバル変数を用いることによって関数間で変数の共有を行う場合の例を擬似コードによって示している。この例では、関数func1及び関数func2のほかに、グローバル変数flagが宣言されている。関数func1はグローバル変数に値の代入を行い、関数func2はグローバル変数の値を参照している。グローバル変数を用いることには、共有する変数を関数の引数によって渡すことなく、変数の共有が行えるという利点がある。しかしながらグローバル変数を用いる方法には、関数の定義とグローバル変数の定義とがヘッダーファイルに記述されている際に課題がある。このようなヘッダーファイルが同一プログラムを構成する複数のソースファイルから読み込まれる場合には、図3に示すように、グローバル変数が複数のソースファイルで定義されることになり、リンク時にエラーになるか、あるいは、本来ならば1つであるはずのグローバル変数がそれぞれ別々の変数として扱われて関数間で変数の共有ができなくなる。このような問題は、重複定義問題として知られている。グローバル変数の代わりにC++のクラスの静的メンバ変数を用いる場合も、同様の課題が生じる。なお、特許文献1には、ネットワーク環境に対してグローバル変数による変数の共有を拡張したものとして、ネットワークに接続された複数のノード間でデータを共有するために、各データを論理名(ネットワークグローバル変数)で定義し、ユーザプログラムは論理名でそのデータを取得することが示されている。
On the other hand, FIG. 2 shows an example in which variables are shared between functions by using global variables in pseudo code. In this example, a global variable flag is declared in addition to the functions func1 and func2. The function func1 assigns a value to the global variable, and the function func2 refers to the value of the global variable. Using a global variable has the advantage that the variable can be shared without passing the shared variable as a function argument. However, the method using the global variable has a problem when the definition of the function and the definition of the global variable are described in the header file. When such a header file is read from a plurality of source files that make up the same program, as shown in FIG. 3, a global variable is defined in the plurality of source files, and an error occurs at the time of linking. Or, a global variable that should have been originally one is treated as a separate variable, and the variable cannot be shared between functions. Such a problem is known as a duplicate definition problem. Similar problems arise when using C ++ class static member variables instead of global variables. In
この重複定義問題を回避する方法として、グローバル変数の定義をヘッダーファイルに記述するのではなく、ソースファイルに記述するという方法がある。グローバル変数の定義をソースファイルにおいて行う場合には、新たなソースファイルを追加するときや、既存のソースファイルにグローバル変数を追加するときなどに、プログラムの構成を複雑にしてしまうといった問題がある。さらにこの方法は、ヘッダーファイルだけから構成されいてオブジェクトファイルを持たないライブラリでは利用できない、といった問題もある。なお、オブジェクトファイルを持たないライブラリには、ヘッダーファイルをリンクするだけで利用できて使い勝手が良いという利点や、ライブラリ開発者がハードウェア固有のオブジェクトファイルを管理しないでよいといった利点があるため、ヘッダーファイルからだけなるライブラリからオブジェクトファイルをも有するライブラリへと変更することは、ライブラリの利用者とライブラリ開発者のどちらにとっても手間が増えるという問題をもたらす。 As a method of avoiding this duplicate definition problem, there is a method of describing the definition of the global variable in the source file instead of describing it in the header file. When global variables are defined in a source file, there is a problem that the program configuration becomes complicated when a new source file is added or when a global variable is added to an existing source file. Furthermore, this method has a problem that it cannot be used in a library that is composed of only header files and does not have object files. A library that does not have an object file has the advantage that it can be used simply by linking the header file and is easy to use, and the library developer does not have to manage hardware-specific object files. Changing from a library consisting only of files to a library having object files also raises the problem that both the user of the library and the library developer increase the effort.
関数間で変数を共有することに関連し、特許文献2は、複数のコントローラ装置の各々ごとの制御プログラムを作成する際に共有データ定義の不整合の検査を行うために、各コントローラ装置に応じたプログラミング環境ごとに共有データ定義支援装置を設けることを開示している。各々の共有データ定義支援装置は、初期状態では同一内容である共有データ管理テーブルと、自装置の共有データ管理テーブルに基づいて生成される共有データ変数宣言テーブルとを備え、自装置及び他装置のこれらのテーブルに基づいて整合性検査を実行する。また特許文献3はソースファイルの再利用を支援する装置を開示しており、この装置では、アクティブソースファイル(編集対象となったソースファイル)から参照可能な定義データを、アクティブソースファイル内で定義されているローカル定義データとアクティブソース以外のソースファイル内で定義されている外部定義データとに区分して、各定義データに関する情報を取得、表示する。これによって利用者は、全ソースファイルで利用可能なグローバル変数も容易に検出可能となり、同一データを意味するグローバル変数の重複等を防ぐことができる。特許文献3に記載された技術は、利用者の介入によってグローバル変数の重複を防ごうとするものである。 In relation to sharing variables between functions, Japanese Patent Laid-Open No. 2004-26883 discloses a method for checking the inconsistency of a shared data definition when creating a control program for each of a plurality of controller devices. Providing a shared data definition support device for each programming environment. Each shared data definition support device includes a shared data management table having the same contents in the initial state, and a shared data variable declaration table generated based on the shared data management table of the own device. A consistency check is performed based on these tables. Patent Document 3 discloses an apparatus that supports the reuse of a source file. In this apparatus, definition data that can be referred to from an active source file (source file to be edited) is defined in the active source file. The information about each definition data is acquired and displayed by classifying the local definition data into external definition data defined in source files other than the active source. As a result, the user can easily detect global variables that can be used in all source files, and can prevent duplication of global variables that mean the same data. The technique described in Patent Document 3 tries to prevent duplication of global variables through user intervention.
さらに異なる複数のプロセス間でのデータ共有を行うものとして、特許文献4には、共有メモリ上に環境変数を配置するとともに、親子関係になくてもよい複数のプロセス間で環境変数を用いて変数を共有することが開示されている。なお、特許文献4に記載のものでは、異なるプロセス間で共有メモリを利用するため、異なるプロセスから共有メモリの場所を特定することを可能にするために、グローバル変数や引数に類する何らかの情報が必要になるものと考えられる。特許文献5には、ネットワークに接続された複数のコンピュータでネットワーク共有変数を共有する際に、型情報を有する共有変数を使用し、共有変数を読み出す関数は環境変数に対する参照(リファレンス)を引数として受け取ることを開示している。
Further, as a method for sharing data between a plurality of different processes,
複数の関数間で変数を共有する技術は知られているものの、それらは、引数あるいはグローバル変数を介するものであるので、上述したような課題を有する。グローバル変数や関数の引数を利用することなく同一プロセス内の異なる複数の関数の間で変数あるいはデータを共有する手法は知られていない。 Although techniques for sharing variables among a plurality of functions are known, they have problems as described above because they are via arguments or global variables. There is no known method for sharing variables or data between different functions in the same process without using global variables or function arguments.
本発明の目的は、同一プロセス内の異なる複数の関数間で、関数の引数及びグローバル変数を利用することなく、変数を共有するための方法及び機構を提供することにある。 It is an object of the present invention to provide a method and mechanism for sharing variables among a plurality of different functions in the same process without using function arguments and global variables.
本発明の例示態様によれば、関数間変数共有方法は、同一プロセス内の複数の関数の間で変数を共有する関数間変数共有方法であって、値を格納して識別子によって値を参照することと値に代入することとができる識別子値記憶部を用い、複数の関数の間で共有される変数が参照されるときに、変数に対応する識別子を用いて識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡すことと、いずれかの関数から値を渡されて変数に代入するときに、変数に対応する識別子を用いて識別子値記憶部に格納されている値を変更することと、を有する。 According to an exemplary aspect of the present invention, an inter-function variable sharing method is an inter-function variable sharing method for sharing a variable among a plurality of functions in the same process, storing a value and referring to the value by an identifier. When a variable shared between multiple functions is referenced using an identifier value storage unit that can be assigned to the value and the value, the identifier corresponding to the variable is stored in the identifier value storage unit. The value stored in the identifier value storage unit using the identifier corresponding to the variable when the value is passed from one of the functions and assigned to the variable. Changing.
本発明の例示態様によれば、関数間変数共有機構は、同一プロセス内の複数の関数の間で変数を共有する関数間変数共有機構であって、値を格納して識別子によって値を参照することと値に代入することとができる識別子値記憶部と、複数の関数の間で共有される変数が参照されるときに、変数に対応する識別子を用いて識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡す識別子値参照部と、変数への代入のためにいずれかの関数から値を渡されたときに、変数に対応する識別子を用いて識別子値記憶部に格納されている値を変更する識別子値変更部と、を有する。 According to an exemplary aspect of the present invention, the inter-function variable sharing mechanism is an inter-function variable sharing mechanism that shares a variable among a plurality of functions in the same process, and stores the value and refers to the value by an identifier. And an identifier value storage unit that can be assigned to a value, and when a variable shared among a plurality of functions is referenced, the identifier value storage unit stores the identifier value using an identifier corresponding to the variable. An identifier value reference part that reads the value and passes it to the caller function, and stores the value in the identifier value storage part using the identifier corresponding to the variable when a value is passed from one of the functions for assignment to the variable And an identifier value changing unit that changes the value being set.
本発明によれば、同一プロセス内の複数の関数間で、関数の引数及びグローバル変数を利用することなく、変数を共有することができるようになる。 According to the present invention, a variable can be shared among a plurality of functions in the same process without using a function argument and a global variable.
次に、本発明の好ましい実施の形態について、図面を参照して説明する。 Next, a preferred embodiment of the present invention will be described with reference to the drawings.
[第1の実施形態]
[構成]
図4は、第1の実施形態の関数間変数共有機構10の構成を示している。図4に示す関数間変数共有機構10は、同一プロセス内の異なる複数の関数の間で変数を共有するために用いられるものであり、値を格納して識別子によってその値を参照することとその値に代入することとができる識別子値記憶部20と、識別子値記憶部20に対してアクセス可能な識別子値変更部40及び識別子値参照部60と、を備えている。識別子値参照部60は、同一プロセス内の複数の関数の間で共有される変数が参照されるときに、その変数に対応する識別子を呼び出し元の関数から受け取り、その識別子を用いて識別子値記憶部20に格納されている値を読み出し、読み出した値を呼び出し元の関数に渡す機能を有する。一方、識別子値変更部40は、変数への代入のために、呼び出し元の関数からその変数に対する識別子と代入すべきものとして指定された値を渡されたときに、渡された識別子を用いて識別子値記憶部20に格納されている値を指定された値に変更する機能を有する。本実施形態において、識別子や値の具体的な形式としては、文字列や整数値などが利用可能であるが、特定の形式のものに限定されるものではない。
[First Embodiment]
[Constitution]
FIG. 4 shows the configuration of the inter-function
本実施形態において、関数間変数共有機構10は、識別子と値のみが受け渡されるものであることを特徴とする。したがって、関数が関数間変数共有機構10を利用することにより、識別子のみを用いて複数の関数の間で値を共有することが可能であり、グローバル変数や関数の引数を使うことなく、変数の共有が可能となる。
In the present embodiment, the inter-function
[動作]
次に、本実施形態の動作について詳しく説明する。本実施形態の動作は、大別すると、複数の関数の間で共有されることとなる変数の値の変更動作と、いずれかの関数からのその変数についての値の参照動作とからなる。
[Operation]
Next, the operation of this embodiment will be described in detail. The operation of the present embodiment is roughly divided into a variable value changing operation that is shared among a plurality of functions and a value reference operation for the variable from one of the functions.
<値の変更>
値の変更では、まず、変数に対して値を代入する関数が、変数に対応する識別子と値の組み合わせを、識別子値変更部40に渡す。次に識別子値変更部40が、識別子値記憶部20に記録されている識別子に対応する値を、関数から渡された値に変更する。
<Change value>
In changing the value, first, a function for assigning a value to the variable passes the identifier and value combination corresponding to the variable to the identifier
<値の参照>
値の参照では、まず、変数の値を参照しようとする関数が、変数に対応する識別子を、識別子値参照部60に渡す。識別子が渡されことにより識別子値参照部60は、識別子値記憶部20に記録されている、識別子に対応する値を取得する。その後、識別子値参照部60は、呼び出し元の関数に取得した値を渡す。
<Reference value>
In referring to a value, first, a function that attempts to refer to the value of a variable passes an identifier corresponding to the variable to the identifier
図5は、上述した第1の実施形態の効果を示している。図示される例では、関数1が識別子として文字列“flag”、値として整数値1を指定して、識別子値変更部40を呼び出す。その結果、識別子値変更部40が値の変更を行い、識別子値記憶部20には識別子“flag”に対する値として1が記録される(図中の「<"flag", 1>」)。
FIG. 5 shows the effect of the first embodiment described above. In the example shown in the figure, the
次に関数2が識別子“flag”を指定して、識別子値参照部60を呼び出す。識別子値参照部60は、識別子値記憶部20から、識別子“flag”に対応する値として、1を取り出し、関数2に返す。以上の動作により、関数1と関数2の間で値が受け渡される。
Next, the
以上の関数間の値の受け渡しのために、識別子と値のみが関数内で利用されている。したがって本実施形態では、グローバル変数や関数の引数など利用せずに、関数間で変数を共有できるという効果が得られていることが分かる。また、これらの関数がヘッダーファイル内に記述されている場合においても、同様に変数を共有できるという効果が得られることは明らかである。本実施形態では、グローバル変数を利用していないため、ヘッダーファイルが複数のソースファイルに読み込まれる場合においても、関数間での変数の共有が可能であるという効果が得られる。 Only identifiers and values are used in functions for passing values between functions. Therefore, in this embodiment, it can be seen that there is an effect that variables can be shared between functions without using global variables or function arguments. In addition, even when these functions are described in the header file, it is clear that the effect that the variables can be shared is obtained. In this embodiment, since a global variable is not used, even when a header file is read into a plurality of source files, an effect that a variable can be shared between functions is obtained.
[第2の実施形態]
図6は、第2の実施形態の関数間変数共有機構10の構成を示している。本実施形態は、環境変数を用いて複数の関数の間で変数を共有するものであり、したがって識別子値記憶部20として、環境変数の記憶領域である環境変数記憶部21を用いている。
[Second Embodiment]
FIG. 6 shows the configuration of the inter-function
環境変数は、複数のプロセス間で値を共有するためにOS(オペレーティングシステム;operating system)などで提供される仕組みであり、Linux(登録商標)やWindows(登録商標)などのOSにおいて一般的に利用されている。環境変数は、プロセスの起動時に、プロセスのメモリ空間上の特定のアドレスに格納される文字列から構成される。文字列は、キーと値との1以上のペア(対)で構成され、これらを変数名及び値として利用することができる。OSは、プロセスの起動時に、親プロセスの環境変数を子プロセスに引き継ぐように、子プロセスのメモリ空間を作成する。これにより、親プロセスで設定した環境変数を子プロセスが参照することができるようになる。このように環境変数は、一般に、親子プロセス間での変数の共有に利用される。 An environment variable is a mechanism provided by an OS (operating system) in order to share a value among a plurality of processes, and is generally used in an OS such as Linux (registered trademark) or Windows (registered trademark). It's being used. The environment variable is composed of a character string stored at a specific address in the memory space of the process when the process is started. The character string is composed of one or more pairs of a key and a value, and these can be used as a variable name and a value. The OS creates a memory space for the child process so that the environment variable of the parent process is inherited to the child process when the process is started. As a result, the child process can refer to the environment variable set in the parent process. As described above, environment variables are generally used for sharing variables between parent and child processes.
本実施形態では、このような環境変数の一般的な利用形態とは異なり、環境変数を同一プロセス内での関数間での変数の共有に利用するという特徴的な利用を行う。具体的には本実施形態は、環境変数はプロセスのメモリ空間中の固定アドレスに置かれるという性質を利用して、この固定アドレスに置かれた環境変数を用いて、同一プロセス内の関数間でデータを共有する。環境変数の設定と参照は識別子と値だけで行うことが可能であるため、本実施形態によれば、グローバル変数や関数の引数を利用しない、関数間変数共有のための仕組みを提供することができる。 In the present embodiment, unlike the general usage form of such environment variables, the environment variable is used for sharing variables between functions in the same process. Specifically, this embodiment uses the property that an environment variable is placed at a fixed address in the memory space of a process, and the environment variable placed at this fixed address is used between functions in the same process. Share data. Since environment variables can be set and referenced only by identifiers and values, according to this embodiment, a mechanism for sharing variables between functions that does not use global variables or function arguments can be provided. it can.
図6に示すように本実施形態の関数間変数共有機構10において、識別子値変更部40は、関数から渡された識別子及び値を文字列に変換する文字列変換部41と、文字列変換部41によって変換された文字列を環境変数として、識別子値記憶部20としての環境変数記憶部21に設定する環境変数設定部42と、を備えている。識別子値参照部60は、環境変数記憶部21にアクセスして識別子に対応する環境変数の値を参照する環境変数参照部61と、環境変数参照部61によって参照された環境変数中に記録されている文字列を値の形式に変換する文字列変換部62と、を備えている。識別子が文字列でない場合には、環境変数参照部61の前に、識別子を文字列に変換するさらになる文字列変換部を設け、この文字列変換部によって文字列に変換された識別子を環境変数参照部61に渡すことが望ましい。
As shown in FIG. 6, in the inter-function
環境変数設定部42と環境変数参照部61の具体的な例としては、それぞれ、Linux(登録商標)におけるsetenv関数とgetenv関数がある。これらによる環境変数の設定、参照は一般によく知られているため、これらの詳細な動作の説明は省略する。第1の実施形態の説明とこれまでの説明から明らかであるため、本実施形態における動作及び効果についての説明を省略する。
Specific examples of the environment
[第3の実施の形態]
図7は、第3の実施形態の関数間変数共有機構10の構成を示している。本実施形態は、識別子値記憶部20として、プロセス間共有メモリ31上のハッシュテーブル32を利用することを特徴とするものである。プロセス間共有メモリは、複数のプロセス間でデータの受け渡し等を行うために共有メモリ空間を作成する機能であり、一般に、OSによって提供されるものである。
[Third Embodiment]
FIG. 7 shows the configuration of the inter-function
プロセス間共有メモリは、key(キー)と呼ばれる一意な識別子(例えばLinux(登録商標)の場合は整数値)を有することができるが、keyを指定して特定のプロセス間共有メモリをプロセスのメモリ空間上にマップし、マップしたアドレスを知ることができる。すなわちkeyを知っていれば、プロセスのメモリ空間上の特定のメモリ領域のアドレスを特定できるということである。例えばkeyをプロセスIDにすれば、プロセスIDはプロセス中の任意の関数で取得することができるため、任意の関数がグローバル変数や関数の引数を使うことなく、特定のメモリ領域のアドレスを取得することができる。このメモリ領域にハッシュテーブルを作成し、関数間で共有したい変数の識別子と値とを格納することで、関数間で変数の共有を行うのが、本実施形態である。なお、本実施形態の説明では、識別子と値との記録にハッシュテーブル32を利用しているが、識別子と値とを記録可能なその他のデータ構造を用いても良いことは明らかである。 The inter-process shared memory can have a unique identifier called a key (for example, an integer value in the case of Linux (registered trademark)), but a specific inter-process shared memory can be designated as a process memory by specifying a key. You can map on space and know the mapped address. That is, if you know the key, you can specify the address of a specific memory area in the process memory space. For example, if the key is a process ID, the process ID can be acquired by any function in the process. Therefore, the arbitrary function acquires the address of a specific memory area without using global variables or function arguments. be able to. In this embodiment, a hash table is created in this memory area, and an identifier and a value of a variable to be shared between functions are stored, so that the variable is shared between functions. In the description of the present embodiment, the hash table 32 is used for recording identifiers and values. However, it is obvious that other data structures capable of recording identifiers and values may be used.
図7に示すように本実施形態の関数間変数共有機構10において、識別子値変更部40は、共有メモリ割り当て部51とハッシュテーブル取得部52とハッシュテーブル更新部53とを有する。
As shown in FIG. 7, in the inter-function
共有メモリ割り当て部51は、特定のkey(例えばプロセスID)に対応するプロセス間共有メモリ31をプロセスのメモリ空間に割り当てる機能を有し、プロセス間共有メモリ31がまだ作成されていない場合はその作成を行う。共有メモリ割り当て部51自体がプロセス間共有メモリ31を作成するのではなく、keyに対応するプロセス間共有メモリ31の作成をOSに対して指示する構成としてもよい。この場合、OSは、プロセス間共有メモリ31がまだ作成されていない場合にはそれを作成し、既に作成されている場合には何も行わない。
The shared
ハッシュテーブル取得部52は、プロセス間共有メモリ31上に作成されたハッシュテーブル32のアドレスを特定する。例えば、プロセス間共有メモリ31の領域の先頭にハッシュテーブル32を配置するといった方法を取ることができる。また、ハッシュテーブル32自体はヒープ領域に確保し、そのアドレスをプロセス間共有メモリ31の先頭に格納するといった方法を用いても良い。また、ハッシュテーブル32がまだ作成されていない場合は、ハッシュテーブル取得部52は、プロセス間共有メモリ31内にハッシュテーブル32を新たに作成する。
The hash
ハッシュテーブル更新部53は、ハッシュテーブル取得部52によって特定されたアドレスを用いて、ハッシュテーブル32中の識別子に対応する値を変更する機能を有する。なお、ハッシュテーブルに格納する識別子と値の形式が、関数から渡される識別子と値の形式と異なる場合には、適切に変換することが望ましい。このような変換を行うために、識別子値変更部40に、識別子及び値をハッシュテーブル32に適した形式に変換してハッシュテーブル更新部53に渡す文字列変換部を備えてもよい。
The hash
一方、識別子値参照部60は、共有メモリ割り当て部71、ハッシュテーブル取得部72及びハッシュテーブル参照部73を備えている。共有メモリ割り当て部71及びハッシュテーブル取得部72は、それぞれ、識別子値変更部40の共有メモリ割り当て部51及びハッシュテーブル取得部52と同一の機能を有する。ハッシュテーブル参照部73は、ハッシュテーブル取得部72により特定されたアドレスを用いて、ハッシュテーブル32中の識別子に対応する値を参照し、呼び出し元の関数に渡す機能を有する。
On the other hand, the identifier
本実施形態の関数間変数共有機構10は、ハッシュテーブル32が不要になったとき(例えばプロセスの終了時など)にプロセス間共有メモリ31を解放する機能を有した共有メモリ解放部を備えていても良い。
The inter-function
第1及び第2の実施形態の説明とこれまでの説明から明らかであるため、本実施形態における動作及び効果についての説明を省略する。 Since it is clear from the description of the first and second embodiments and the description so far, description of operations and effects in this embodiment is omitted.
以上説明した各実施形態によれば、ヘッダーファイルのみで構成されたライブラリにおいても複数の関数間で変数を共有できるようになる。したがって、利用者の利便性が高いライブラリを提供することや、開発者の負担が少ないライブラリを提供するといったことが可能となる。 According to each embodiment described above, a variable can be shared among a plurality of functions even in a library composed only of header files. Therefore, it is possible to provide a library that is highly convenient for the user and to provide a library that places less burden on the developer.
上述した各実施形態の関数間変数共有機構10において、識別子値記憶部20としては、異なる複数の関数を含むプロセスが実行されるコンピュータの記憶装置内の所定の領域を用いることができる。識別子値変更部40及び識別子値参照部60は、それぞれ専用のハードウェアによって構成することも可能ではあるが、関数間で変数を共有するためのプログラムを前述したプロセスを実行するコンピュータ上で実行させることによって実現することができる。このように関数間変数共有機構10をコンピュータソフトウェアで実現する場合には、そのためのプログラムをコンピュータに読み込ませてコンピュータに実行させればよい。このプログラムは、通信インタフェースなどを介して外部装置から読み込まれ、あるいは、コンピュータ読み取り可能な記憶媒体から読み込まれ、予め、記憶装置格納される。さらには、上述した関数間変数共有機構10の機能は、コンピュータのOSにおいて予め実装することもできる。
In the inter-function
次に、具体的な実施例を用いて上述した実施形態の動作を説明する。ここで説明例は、プログラム中の任意の区間の時間を計測するタイマライブラリをヘッダーファイルのみで構成する場合の例である。 Next, the operation of the above-described embodiment will be described using a specific example. Here, the explanation example is an example in the case where the timer library for measuring the time of an arbitrary section in the program is configured only by the header file.
ここでは、ライブラリは以下の3つの関数から構成されるものとし。いずれもtimer.h内で定義されているものとする。 Here, it is assumed that the library consists of the following three functions. Both are defined in timer.h.
timer_begin(int id) 時間計測の開始
timer_end(int id) 時間計測の終了
timer_output() 測定結果の出力
これらの関数は、図9に示すように利用される。この例では、プログラムはそれぞれC言語で記載された関数を示すmain.c、func1.c及びfunc2.cの3つのファイルからなっており、それぞれがtimer.hをインクルードしている。timer.hは、ヘッダーファイルのみで構成されたタイマライブラリである。これらのプログラムでは、関数func1及び関数func2内の特定の区間の時間を計測するため、上記の時間計測関数がそれぞれの関数内に挿入されている。また、計測結果を出力するため、main関数の最後に結果出力関数timer_output()が呼び出されており、func1とfunc2の実行時間の計測を行って、その結果を出力するようになっている。
timer_begin (int id) Time measurement start
timer_end (int id) End of time measurement
timer_output () Measurement result output These functions are used as shown in FIG. In this example, the program consists of three files, main.c, func1.c, and func2.c, each indicating a function written in C language, each of which includes timer.h. timer.h is a timer library composed only of header files. In these programs, in order to measure the time of a specific section in the function func1 and the function func2, the above time measurement function is inserted in each function. In order to output the measurement result, the result output function timer_output () is called at the end of the main function, and the execution time of func1 and func2 is measured and the result is output.
一般に、時間計測を行う際は、計測した値を記録し、それをプログラムの最後で出力するという利用方法が取られる。計測を行うたびに出力を行うと、出力に要する処理時間がプログラムの実行時間に影響を与えて、正しく時間計測が行えないことなどの問題があるためである。したがって、計測した値を記録しておく領域が必要となり、時間計測関数(本例ではtimer_begin関数やtimer_end関数)や出力関数(本例ではtimer_output関数)は、その領域を特定できる必要がある。すなわち、これらの関数間で領域を共有する必要がある。 In general, when measuring time, a method of recording the measured value and outputting it at the end of the program is used. This is because if the output is performed every time measurement is performed, the processing time required for the output affects the execution time of the program, and the time cannot be measured correctly. Therefore, an area for recording the measured value is required, and the time measurement function (timer_begin function and timer_end function in this example) and the output function (timer_output function in this example) need to be able to specify the area. That is, it is necessary to share an area between these functions.
一方で、時間計測ライブラリの利用者にとっては時間の計測が目的であり、測定結果を記録するための領域には関心がない。したがって、ライブラリ利用者がそのような領域の管理を行う必要がないことが望ましい。本実施例の時間計測ライブラリは、上記のように計測区間を指定するIDのみを引数としてとり、ライブラリ利用者が計測結果記録用の領域を扱う必要がない利便性の高いライブラリとなっている。 On the other hand, users of the time measurement library are interested in measuring time, and are not interested in the area for recording the measurement results. Therefore, it is desirable that the library user does not need to manage such areas. The time measurement library according to the present embodiment is a highly convenient library that takes only an ID for specifying a measurement section as an argument as described above and does not require the library user to handle a measurement result recording area.
図9は、この実施例での時間計測ライブラリtimer.hを示している。ここでは環境変数を用いて関数間での変数の共有を行うものとする。したがって、識別子値記憶部20としては、環境変数の記憶領域すなわち環境変数記憶部21が用いられる。時間計測ライブラリtimer.hのソースコードのうち、get関数が識別子値参照部60の機能を実行し、set関数が識別子値変更部40の機能を実行する。図9に示すように、get関数は、識別子として文字列nameを引数として受け取り、getenv関数を呼び出して、環境変数nameの値を取得する。getenv関数はLinux(登録商標)などが備えている一般的なものであるから説明を省略する。getenv関数によりnameに対応する文字列が得られるため、get関数はその後、取得した値をポインタ値に変換して返却する。文字列からポインタ値への変更方法は周知のものであるので、ここでは説明を省略する。環境変数が設定されていない場合は、get関数はNULL(ヌル)を返却する。一方、set関数は、識別子として文字列name、値としてポインタ値ptrを受け取る。set関数は、ptrを文字列に変換し、setenv関数を呼び出すことによって、環境変数に値を格納する。この実施例のget関数及びset関数は、渡されたnameをそのまま環境変数として利用しているが、プレフィックスをつけるなどにより、既存の環境変数との重複を避けるようにしてもよい。
FIG. 9 shows a time measurement library timer.h in this embodiment. Here, it is assumed that variables are shared between functions using environment variables. Therefore, as the identifier
次にこの実施例の時間計測関数について説明する。timer_begin関数は、まず時刻を計測し、それを記録するという動作を行う。get_clock関数の呼び出し部分が時刻の計測であるが、これは、一般的なOSは備えられている関数であるので、その詳細についての説明は省略する。計測後、get関数を呼び出して、計測結果を格納するためのテーブルのアドレスを取得する。もしテーブルがまだ作成されていない場合(NULLの場合)、新たにテーブルを作成して、set関数を呼び出して、テーブルのアドレスを格納する。最後にテーブルに測定値を書き込む。timer_end関数は、同様にまず時間計測を行う。その後、get関数を呼び出して、結果格納用のテーブルを取得し、テーブルに値を格納する。timer_output関数は、結果格納用のテーブルをget関数によって取得し、結果出力を行う。このようにget関数及びset関数を用いることによって、この実施例では、timer_begin関数、timer_end関数及びtimer_output関数の各関数間で、グローバル変数や引数を用いることなく、結果格納用テーブルの共有を行うことができている。 Next, the time measurement function of this embodiment will be described. The timer_begin function performs an operation of first measuring time and recording it. The calling part of the get_clock function is time measurement, but since this is a function provided with a general OS, a detailed description thereof will be omitted. After the measurement, the get function is called to acquire the address of the table for storing the measurement result. If the table has not yet been created (if NULL), create a new table and call the set function to store the table address. Finally, write the measured values to the table. Similarly, the timer_end function first measures time. After that, the get function is called to obtain the result storage table, and the value is stored in the table. The timer_output function obtains a result storage table with the get function and outputs the result. By using the get function and the set function in this way, in this embodiment, the result storage table can be shared between the timer_begin function, the timer_end function, and the timer_output function without using global variables and arguments. Is done.
ところでこの実施例では、図8に示したように、timer.hは複数のファイル(すなわち、main.c、func1.c及びfunc2.c)でインクルードされているため、timer.hにおいてグローバル変数を利用した場合は、重複定義の問題が起こることは明らかである。このように、本発明に基づく方法を用いることによって、この実施例では、ライブラリの利用者にとっての利便性が高い時間計測ライブラリを提供できるといった効果がある。また、ライブラリの開発者にとっては、オブジェクトファイルを管理しなくて良いといった効果もある。 In this embodiment, as shown in FIG. 8, timer.h is included in a plurality of files (that is, main.c, func1.c, and func2.c). Obviously, the problem of over-definition will occur when used. Thus, by using the method according to the present invention, in this embodiment, there is an effect that it is possible to provide a time measurement library that is highly convenient for the library user. For library developers, there is also an effect that object files need not be managed.
上記の実施形態及び実施例の一部または全部は、以下の付記のようにも記載されうるが、以下には限られない。 Part or all of the above embodiments and examples can be described as in the following supplementary notes, but are not limited thereto.
[付記1]
同一プロセス内の複数の関数の間で変数を共有する関数間変数共有方法であって、
値を格納して識別子によって前記値を参照することと前記値に代入することとができる識別子値記憶部を用い、前記複数の関数の間で共有される変数が参照されるときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡すことと、
いずれかの関数から値を渡されて前記変数に代入するときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を変更することと、
を有する方法。
[Appendix 1]
An inter-function variable sharing method for sharing variables among a plurality of functions in the same process,
When an identifier value storage unit that can store a value and refer to the value by an identifier and assign to the value is referred to, and the variable shared among the plurality of functions is referred to, the variable Reading the value stored in the identifier value storage unit using the identifier corresponding to the caller function,
When a value is passed from any function and assigned to the variable, the value stored in the identifier value storage unit is changed using an identifier corresponding to the variable;
Having a method.
[付記2]
前記識別子値記憶部として環境変数の記憶領域を使用し、環境変数を定義して前記識別子として使用する、付記1に記載の方法。
[Appendix 2]
The method according to
[付記3]
前記識別子値記憶部としてプロセス間共有メモリを使用する、付記1に記載の方法。
[Appendix 3]
The method according to
[付記4]
前記識別子値記憶部として、前記プロセス間共有メモリ内に構築されたハッシュテーブルを使用し、該ハッシュテーブル内に前記識別子と前記値とを格納する、付記3に記載の方法。
[Appendix 4]
4. The method according to appendix 3, wherein a hash table constructed in the inter-process shared memory is used as the identifier value storage unit, and the identifier and the value are stored in the hash table.
[付記5]
前記識別子値記憶部に、前記識別子と前記値とを組にして格納する、付記1に記載の方法。
[Appendix 5]
The method according to
[付記6]
前記同一プロセス内の複数の関数は、ヘッダーファイル内に記述された複数の関数を含む、付記1乃至5のいずれか1項に記載の方法。
[Appendix 6]
The method according to any one of
[付記7]
前記同一プロセス内の複数の関数は、ヘッダーファイルのみで構成されるライブラリにおける複数のライブラリ関数を含む、付記1乃至6のいずれか1項に記載の方法。
[Appendix 7]
The method according to any one of
[付記8]
同一プロセス内の複数の関数の間で変数を共有する関数間変数共有機構であって、
値を格納して識別子によって前記値を参照することと前記値に代入することとができる識別子値記憶部と、
前記複数の関数の間で共有される変数が参照されるときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡す識別子値参照部と、
前記変数への代入のためにいずれかの関数から値を渡されたときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を変更する識別子値変更部と、
を有する機構。
[Appendix 8]
An inter-function variable sharing mechanism that shares variables among multiple functions in the same process,
An identifier value storage unit for storing a value and referring to the value by an identifier and assigning to the value;
When a variable shared between the plurality of functions is referred to, an identifier value reference that reads a value stored in the identifier value storage unit using an identifier corresponding to the variable and passes the value to the calling function And
An identifier value changing unit that changes a value stored in the identifier value storage unit using an identifier corresponding to the variable when a value is passed from any function for assignment to the variable;
With mechanism.
[付記9]
前記識別子値記憶部として環境変数の記憶領域を使用し、
前記識別子値変更部は、前記関数から渡された前記識別子及び前記値を文字列に変換する第1の文字列変換部と、前記第1の文字列変換部によって変換された文字列を環境変数として前記記憶領域に設定する環境変数設定部と、を有し、
前記識別子値参照部は、前記記憶領域にアクセスして前記識別子に対応する環境変数を参照する環境変数参照部と、前記環境変数参照部によって参照された前記環境変数中に記録されている文字列を値の形式に変換する第2の文字列変換部と、を有する、付記8に記載の機構。
[Appendix 9]
Using an environment variable storage area as the identifier value storage unit,
The identifier value changing unit includes: a first character string converting unit that converts the identifier and the value passed from the function into a character string; and a character string converted by the first character string converting unit is an environment variable An environment variable setting unit that sets the storage area as
The identifier value reference unit includes an environment variable reference unit that accesses the storage area and refers to an environment variable corresponding to the identifier, and a character string recorded in the environment variable referenced by the environment variable reference unit The mechanism according to appendix 8, further comprising: a second character string conversion unit that converts the character string into a value format.
[付記10]
前記識別子値参照部は、前記識別子を文字列に変換して前記環境変数参照部に渡す第3の文字列変換部を有する、付記9に記載の機構。
[Appendix 10]
The mechanism according to appendix 9, wherein the identifier value reference unit includes a third character string conversion unit that converts the identifier into a character string and passes the identifier to the environment variable reference unit.
[付記11]
前記識別子値記憶部として、プロセス間共有メモリを使用する、付記8に記載の機構。
[Appendix 11]
The mechanism according to appendix 8, wherein an inter-process shared memory is used as the identifier value storage unit.
[付記12]
前記識別子値記憶部として、プロセス間共有メモリを使用し、
前記識別子値変更部は、前記プロセスのメモリ空間に前記プロセス間共有メモリを割り当てる第1の共有メモリ割り当て部と、前記プロセス間共有メモリ上のハッシュテーブルのアドレスを特定する第1のハッシュテーブル取得部と、前記特定されたアドレスを用いて前記ハッシュテーブル中の前記識別子に対応する値を変更するハッシュテーブル更新部と、を有し、
前記識別子値参照部は、前記プロセスのメモリ空間に前記プロセス間共有メモリを割り当てる第2の共有メモリ割り当て部と、前記プロセス間共有メモリ上の前記ハッシュテーブルのアドレスを特定する第2のハッシュテーブル取得部と、前記第2のハッシュテーブル取得部により特定された前記アドレスを用いて前記ハッシュテーブル中の前記識別子に対応する値を参照して前記関数に渡すハッシュテーブル参照部と、を有する、付記8に記載の機構。
[Appendix 12]
Using an inter-process shared memory as the identifier value storage unit,
The identifier value change unit includes a first shared memory allocation unit that allocates the inter-process shared memory to the memory space of the process, and a first hash table acquisition unit that identifies an address of a hash table on the inter-process shared memory And a hash table update unit that changes a value corresponding to the identifier in the hash table using the specified address,
The identifier value reference unit includes a second shared memory allocation unit that allocates the inter-process shared memory to the memory space of the process, and a second hash table acquisition that identifies an address of the hash table on the inter-process shared memory And a hash table reference unit that refers to a value corresponding to the identifier in the hash table using the address specified by the second hash table acquisition unit and passes the value to the function. The mechanism described in.
[付記13]
前記識別子値変更部は、前記識別子及び値を前記ハッシュテーブルに適した形式に変換して前記ハッシュテーブル更新部に渡す文字列変換部を有する、付記12に記載の機構。
[Appendix 13]
The mechanism according to appendix 12, wherein the identifier value changing unit includes a character string conversion unit that converts the identifier and value into a format suitable for the hash table and passes the converted value to the hash table update unit.
[付記14]
前記識別子値記憶部に、前記識別子と前記値とを組にして格納する、付記8に記載の機構。
[Appendix 14]
The mechanism according to appendix 8, wherein the identifier and the value are stored as a set in the identifier value storage unit.
[付記15]
前記同一プロセス内の複数の関数は、ヘッダーファイル内に記述された複数の関数を含む、付記8乃至14のいずれか1項に記載の機構。
[Appendix 15]
The mechanism according to any one of appendices 8 to 14, wherein the plurality of functions in the same process includes a plurality of functions described in a header file.
[付記16]
前記同一プロセス内の複数の関数は、ヘッダーファイルのみで構成されるライブラリにおける複数のライブラリ関数を含む、付記8乃至15のいずれか1項に記載の機構。
[Appendix 16]
The mechanism according to any one of appendices 8 to 15, wherein the plurality of functions in the same process includes a plurality of library functions in a library configured only by a header file.
[付記17]
コンピュータにおいて同一プロセス内の複数の関数の間で変数を共有するためのプログラムであって、
前記コンピュータの記憶領域を、値を格納して識別子によって前記値を参照することと前記値に代入することとができる識別子値記憶部として使用させ、
前記コンピュータを、
前記複数の関数の間で共有される変数が参照されるときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡す識別子値参照手段、及び
前記変数への代入のためにいずれかの関数から値を渡されたときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を変更する識別子値変更手段、
として機能させるプログラム。
[Appendix 17]
A program for sharing variables among a plurality of functions in the same process in a computer,
The storage area of the computer is used as an identifier value storage unit that can store a value and refer to the value by an identifier and assign the value to the value.
The computer,
When a variable shared between the plurality of functions is referred to, an identifier value reference that reads a value stored in the identifier value storage unit using an identifier corresponding to the variable and passes the value to the calling function And an identifier value change for changing a value stored in the identifier value storage unit using an identifier corresponding to the variable when a value is passed from any function for assignment to the variable means,
Program to function as.
10 関数間変数共有機構
20 識別子値記憶部
21 環境変数記憶部
31 プロセス間共有メモリ
32 ハッシュテーブル
40 識別子値変更部
41,62 文字列変換部
42 環境変数設定部
51,71 共有メモリ割り当て部
52,72 ハッシュテーブル取得部
53 ハッシュテーブル更新部
60 識別子値参照部
61 環境変数参照部
73 ハッシュテーブル参照部
10 Inter-function
Claims (10)
値を格納して識別子によって前記値を参照することと前記値に代入することとができる識別子値記憶部を用い、前記複数の関数の間で共有される変数が参照されるときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡すことと、
いずれかの関数から値を渡されて前記変数に代入するときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を変更することと、
を有する方法。 An inter-function variable sharing method for sharing variables among a plurality of functions in the same process,
When an identifier value storage unit that can store a value and refer to the value by an identifier and assign to the value is referred to, and the variable shared among the plurality of functions is referred to, the variable Reading the value stored in the identifier value storage unit using the identifier corresponding to the caller function,
When a value is passed from any function and assigned to the variable, the value stored in the identifier value storage unit is changed using an identifier corresponding to the variable;
Having a method.
値を格納して識別子によって前記値を参照することと前記値に代入することとができる識別子値記憶部と、
前記複数の関数の間で共有される変数が参照されるときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡す識別子値参照部と、
前記変数への代入のためにいずれかの関数から値を渡されたときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を変更する識別子値変更部と、
を有する機構。 An inter-function variable sharing mechanism that shares variables among multiple functions in the same process,
An identifier value storage unit for storing a value and referring to the value by an identifier and assigning to the value;
When a variable shared between the plurality of functions is referred to, an identifier value reference that reads a value stored in the identifier value storage unit using an identifier corresponding to the variable and passes the value to the calling function And
An identifier value changing unit that changes a value stored in the identifier value storage unit using an identifier corresponding to the variable when a value is passed from any function for assignment to the variable;
With mechanism.
前記識別子値変更部は、前記関数から渡された前記識別子及び前記値を文字列に変換する第1の文字列変換部と、前記第1の文字列変換部によって変換された文字列を環境変数として前記記憶領域に設定する環境変数設定部と、を有し、
前記識別子値参照部は、前記記憶領域にアクセスして前記識別子に対応する環境変数を参照する環境変数参照部と、前記環境変数参照部によって参照された前記環境変数中に記録されている文字列を値の形式に変換する第2の文字列変換部と、を有する、請求項7に記載の機構。 Using an environment variable storage area as the identifier value storage unit,
The identifier value changing unit includes: a first character string converting unit that converts the identifier and the value passed from the function into a character string; and a character string converted by the first character string converting unit is an environment variable An environment variable setting unit that sets the storage area as
The identifier value reference unit includes an environment variable reference unit that accesses the storage area and refers to an environment variable corresponding to the identifier, and a character string recorded in the environment variable referenced by the environment variable reference unit The mechanism according to claim 7, further comprising: a second character string conversion unit that converts the character string into a value format.
前記識別子値変更部は、前記プロセスのメモリ空間に前記プロセス間共有メモリを割り当てる第1の共有メモリ割り当て部と、前記プロセス間共有メモリ上のハッシュテーブルのアドレスを特定する第1のハッシュテーブル取得部と、前記特定されたアドレスを用いて前記ハッシュテーブル中の前記識別子に対応する値を変更するハッシュテーブル更新部と、を有し、
前記識別子値参照部は、前記プロセスのメモリ空間に前記プロセス間共有メモリを割り当てる第2の共有メモリ割り当て部と、前記プロセス間共有メモリ上の前記ハッシュテーブルのアドレスを特定する第2のハッシュテーブル取得部と、前記第2のハッシュテーブル取得部により特定された前記アドレスを用いて前記ハッシュテーブル中の前記識別子に対応する値を参照して前記関数に渡すハッシュテーブル参照部と、を有する、請求項7に記載の機構。 Using an inter-process shared memory as the identifier value storage unit,
The identifier value change unit includes a first shared memory allocation unit that allocates the inter-process shared memory to the memory space of the process, and a first hash table acquisition unit that identifies an address of a hash table on the inter-process shared memory And a hash table update unit that changes a value corresponding to the identifier in the hash table using the specified address,
The identifier value reference unit includes a second shared memory allocation unit that allocates the inter-process shared memory to the memory space of the process, and a second hash table acquisition that identifies an address of the hash table on the inter-process shared memory And a hash table reference unit that refers to a value corresponding to the identifier in the hash table using the address specified by the second hash table acquisition unit and passes the value to the function. 8. The mechanism according to 7.
前記コンピュータの記憶領域を、値を格納して識別子によって前記値を参照することと前記値に代入することとができる識別子値記憶部として使用させ、
前記コンピュータを、
前記複数の関数の間で共有される変数が参照されるときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を読み出して呼び出し元の関数に渡す識別子値参照手段、及び
前記変数への代入のためにいずれかの関数から値を渡されたときに、前記変数に対応する識別子を用いて前記識別子値記憶部に格納されている値を変更する識別子値変更手段、
として機能させるプログラム。 A program for sharing variables among a plurality of functions in the same process in a computer,
The storage area of the computer is used as an identifier value storage unit that can store a value and refer to the value by an identifier and assign the value to the value.
The computer,
When a variable shared between the plurality of functions is referred to, an identifier value reference that reads a value stored in the identifier value storage unit using an identifier corresponding to the variable and passes the value to the calling function And an identifier value change for changing a value stored in the identifier value storage unit using an identifier corresponding to the variable when a value is passed from any function for assignment to the variable means,
Program to function as.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2015066131A JP2016186697A (en) | 2015-03-27 | 2015-03-27 | Method and mechanism for sharing variable among functions |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2015066131A JP2016186697A (en) | 2015-03-27 | 2015-03-27 | Method and mechanism for sharing variable among functions |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2016186697A true JP2016186697A (en) | 2016-10-27 |
Family
ID=57203280
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2015066131A Pending JP2016186697A (en) | 2015-03-27 | 2015-03-27 | Method and mechanism for sharing variable among functions |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2016186697A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110275451A (en) * | 2018-03-15 | 2019-09-24 | 欧姆龙株式会社 | Development support apparatus, development supporting method and recording medium |
CN112272821A (en) * | 2018-07-03 | 2021-01-26 | 欧姆龙株式会社 | Control device and control method |
-
2015
- 2015-03-27 JP JP2015066131A patent/JP2016186697A/en active Pending
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110275451A (en) * | 2018-03-15 | 2019-09-24 | 欧姆龙株式会社 | Development support apparatus, development supporting method and recording medium |
CN110275451B (en) * | 2018-03-15 | 2022-06-14 | 欧姆龙株式会社 | Development support device, development support method, and recording medium |
CN112272821A (en) * | 2018-07-03 | 2021-01-26 | 欧姆龙株式会社 | Control device and control method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9600272B2 (en) | Hierarchical directives-based management of runtime behaviors | |
KR101786156B1 (en) | Compile-time bounds checking for user-defined types | |
EP3123316B1 (en) | Supporting dynamic behavior in statically compiled programs | |
US9836290B2 (en) | Supporting dynamic behavior in statically compiled programs | |
KR102104695B1 (en) | Software interface for a hardware device | |
JP5957006B2 (en) | Extensible data parallel semantics | |
TW201820131A (en) | Process management method and apparatus | |
US8935686B2 (en) | Error-code and exception-based function dispatch tables | |
KR20160003485A (en) | Automatic code generation for remote procedure call | |
EP2941694B1 (en) | Capability based device driver framework | |
Niephaus et al. | Towards polyglot adapters for the graalvm | |
JP2016186697A (en) | Method and mechanism for sharing variable among functions | |
KR20190060561A (en) | THE INTERGRATED IoT PROGRAMMING METHOD AND SYSTEM WITH SELECTIVE ABSTRACTION OF THIRD-PARTY DEVICES | |
EP2941695B1 (en) | High throughput low latency user mode drivers implemented in managed code | |
Matz et al. | Automated partitioning of data-parallel kernels using polyhedral compilation | |
Fan et al. | Advanced Memory Checking for MPI Parallel Applications Using MemPin | |
Azevedo et al. | Building Platform Models with SystemC |