JP2005346272A - Memory-using method for data of structure-type array - Google Patents
Memory-using method for data of structure-type array Download PDFInfo
- Publication number
- JP2005346272A JP2005346272A JP2004163479A JP2004163479A JP2005346272A JP 2005346272 A JP2005346272 A JP 2005346272A JP 2004163479 A JP2004163479 A JP 2004163479A JP 2004163479 A JP2004163479 A JP 2004163479A JP 2005346272 A JP2005346272 A JP 2005346272A
- Authority
- JP
- Japan
- Prior art keywords
- data
- memory
- variable
- structure type
- type array
- 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
本発明は、例えば、C言語などのプログラムデータに使用される構造体型配列のデータのメモリ使用方法に関する。 The present invention relates to a method of using a memory of structure type array data used for program data such as C language.
具体的には、C言語などのプログラムデータに使用される構造体型の配列においてunsigned型データをアクセスする際のメモリ使用量を削減するものである。ソフトウェアによる信号処理を行うデジタル家電などの、処理系に依存しないソフトウェアの流用性を重視する分野に関する。 Specifically, it reduces the amount of memory used when accessing unsigned type data in a structure type array used for program data such as C language. The present invention relates to a field that places importance on the applicability of software that does not depend on processing systems, such as digital home appliances that perform signal processing using software.
構造体型の配列の場合、従来の手法では図9に示すように構造体型の宣言91による1つの変数を示すメンバ92,93,94,95,96,97に対し1つのデータ98を割り当てるようにしていた。従って、構造体に含まれるデータ数が増えるほどメモリ使用量が増加することとなる。
In the case of a structure type array, in the conventional method, as shown in FIG. 9, one
また、従来の技術の構造体型の配列のメモリ使用装置の例を図10に示す。図10において、従来のメモリ使用装置102は、制御手段101及び図示しないプログラムにより制御され、構造体型のメンバ92,93,94,95,96,97を記憶するメモリ103と、構造体型のメンバ92,93,94,95,96,97を読み出して保持するレジスタ104と、構造体型のメンバ92,93,94,95,96,97及びこれらを割り当てたデータ98を記憶するメモリ105を備えていた。
Further, FIG. 10 shows an example of a conventional memory-type device using a structure type array. In FIG. 10, a conventional memory using device 102 is controlled by the control means 101 and a program (not shown), and stores a
また、図11に示すように、1つの変数の何ビットを使うかを決めるビットフィールドを用いた場合、構造体型の宣言111による変数112,113,114,115をビット単位で取り扱うことができるので1つの変数で複数のデータをパックしてメモリ116に記憶することができるが、この場合は処理系によってデータの取り扱われ方が大きく異なってしまう。
In addition, as shown in FIG. 11, when a bit field that determines how many bits of one variable are used, the
図12に示すように、構造体型の宣言121による変数122,123,124,125をビット単位で割り当てたフィールドがメモリ126内の右から左に割り当てられるのか、左から右へ割り当てられるのかは処理系のコンパイラによって異なる。
As shown in FIG. 12, whether a field in which
また、図13に示すように、構造体型の宣言131による変数132,133,134,135,136をビット単位で割り当てたフィールドがメモリ137内に記憶する際に、138で示すように、このビットフィールドの設定が変数の境界にまたがることが許されるかどうかも処理系によって異なる。そのため、ビットフィールドを用いる方法は、もともとビットフィールドの外部で定義されたデータを取り扱う使い方には向いていないものであった。
Further, as shown in FIG. 13, when a field to which
また、図14に示すように、構造体型の宣言141による変数142,143,144,145として共用体を用いた場合では、1つの記憶領域で異なった型をもつ変数データを取り扱うことができる。このため、146に示すように任意の組み合わせが可能となり、147に示すように保持できるデータは1つだけなのでシーケンシャルなアクセスが可能となる。
As shown in FIG. 14, when unions are used as the
しかし、同時に1つの記憶領域に異なった複数のデータを共有させることはできない。このため、148に示すように非排他的となり、149に示すように同時に異なる2つのデータを書き込むと、最後に書き込んだデータのみが保持されるので、はじめのデータは残らないことになる。 However, a plurality of different data cannot be shared simultaneously in one storage area. For this reason, it becomes non-exclusive as shown at 148, and when two different data are written at the same time as shown at 149, only the last written data is held, so the first data does not remain.
構造体からデータを読み出す場合の従来手法のフローチャートを図15に示す。構造体へデータを書き込む場合の従来手法のフローチャートを図16へ示す。フローチャートのそれぞれの動作について説明する。 FIG. 15 shows a flowchart of a conventional method for reading data from a structure. FIG. 16 shows a flowchart of a conventional method for writing data to a structure. Each operation of the flowchart will be described.
読み出し時には、図15において、構造体のメンバから読み出すデータをメモリからレジスタにロードする(F41)。
次に、レジスタから、読み出したデータを保持するメモリ上の変数にストアする(F42)。
At the time of reading, in FIG. 15, data to be read from the structure member is loaded from the memory into the register (F41).
Next, the data is read from the register and stored in a memory variable that holds the read data (F42).
また、書き込み時には、図16において、構造体のメンバへ書き込むデータをメモリからレジスタにロードする(F51)。
次に、レジスタから、書き込むデータをメモリ上の構造体のメンバへストアする(F52)。
At the time of writing, in FIG. 16, data to be written to the structure member is loaded from the memory to the register (F51).
Next, the data to be written is stored in the structure member on the memory from the register (F52).
従来のC言語によるプログラム例を下記に示す。下記の数1のような構造体が宣言されているとする。
An example of a conventional C language program is shown below. Assume that a structure like the following
[数1]
typedef struct {
unsigned int data_a;
char data_b;
} STRUCT_DATA;
[Equation 1]
typedef struct {
unsigned int data_a;
char data_b;
} STRUCT_DATA;
数1は、構造体の宣言として、符号ビットのない整数型のデータaと、符号のあるデータbとがSTRUCT_DATAの名前が付けられていることを示している。
さらに構造体が下記の数2のような配列として宣言されているとする。
Furthermore, it is assumed that the structure is declared as an array as shown in
[数2]
STRUCT_DATA tmp_data[120];
[Equation 2]
STRUCT_DATA tmp_data [120];
数2は、STRUCT_DATAの数として120ビットの実際の記憶領域を確保することを示している。
ここで、読み出し処理時には、下記の数3のような読み出し動作を行う。
Here, at the time of the reading process, a reading operation as shown in the following
[数3]
void read_data(STRUCT_DATA *s_data, short index, unsigned int*read_a, char *read_b){
*read_a = s_data[index]->data_a;
*read_b = s_data[index]->data_b;
return;
}
[Equation 3]
void read_data (STRUCT_DATA * s_data, short index, unsigned int * read_a, char * read_b) {
* read_a = s_data [index]->data_a;
* read_b = s_data [index]->data_b;
return;
}
数3は、STRUCT_DATAとして、ポインタのアドレスで示されるデータaとデータbを読み出す動作を示している。
また、書き込み処理時には、下記の数4のような書き込み動作を行う。
Further, during the writing process, a writing operation as shown in the following
[数4]
void write_data(STRUCT_DATA *s_data, short index, unsigned intwrite_a, char write_b){
s_data[index]->data_a = write_a;
s_data[index]->data_b = write_b;
return;
}
[Equation 4]
void write_data (STRUCT_DATA * s_data, short index, unsigned intwrite_a, char write_b) {
s_data [index]-> data_a = write_a;
s_data [index]-> data_b = write_b;
return;
}
数4は、STRUCT_DATAとして、ポインタのアドレスで示されるデータaとデータbを書き込む動作を示している。
なお、一般的なメモリの使用方法として、本出願人による特許文献1に示す技術がある。
As a general method of using a memory, there is a technique shown in
上述した従来の手法では、構造体の変数を示すメンバが多いほど配列のメモリ使用量が大きくなるという不都合があった。また、共用体を用いた場合では、1つの記憶領域に対して同時に複数のデータを取り扱うことができないという不都合があった。また、ビットフィールドを用いた場合では、データの取り扱われ方が処理系に依存するため外部で定義されたデータの取り扱いには向かないという不都合があった。 The conventional method described above has a disadvantage that the memory usage of the array increases as the number of members indicating the variables of the structure increases. Further, when a union is used, there is a disadvantage that a plurality of data cannot be handled simultaneously for one storage area. Further, when the bit field is used, there is a disadvantage that the way of handling the data depends on the processing system and is not suitable for handling the data defined outside.
そこで、本発明は、構造体の変数配列によるメモリ使用量を低減し、1つの記憶領域に対して同時に複数のデータの取り扱いを可能とし、外部で定義されたデータの取り扱いも容易にすることができる構造体型配列のデータのメモリ使用方法の提供を目的とするものである。 Therefore, the present invention reduces the amount of memory used by the variable array of structures, enables the handling of a plurality of data simultaneously for one storage area, and facilitates the handling of data defined externally. An object of the present invention is to provide a method of using memory of structure type array data that can be generated.
上記課題を解決し、本発明の目的を達成するため、本発明の構造体型配列のデータのメモリ使用方法は、メモリに対して使用するエリアを設定し、メモリの全エリアにおけるある変数を使用するエリアを設定したときの余りのエリアを求め、余りのエリアに応じてメモリに対して他の変数の使用を許可し、メモリに対して書き込まれる関数に使用される変数の書き込み処理手順を決定し、書き込み処理手順に従って他の変数をある変数と合成し、合成された変数をある変数に対応するある変数として記述するものである。 In order to solve the above-described problems and achieve the object of the present invention, the method of using the data of the structure type array of the present invention sets an area to be used for the memory and uses a certain variable in the entire area of the memory. Find the surplus area when setting the area, allow the use of other variables for the memory according to the surplus area, and determine the procedure for writing variables used for functions written to the memory. According to the write processing procedure, another variable is synthesized with a certain variable, and the synthesized variable is described as a certain variable corresponding to the certain variable.
また、本発明の構造体型配列のデータのメモリ使用方法は、メモリに対して使用するエリアを設定し、メモリの全エリアにおけるある変数を使用するエリアを設定したときの余りのエリアを求め、余りのエリアに応じてメモリに対して他の変数の使用を許可し、メモリに対して他の変数がある変数と合成して書き込まれる関数に使用される変数の読み出し処理手順を決定し、読み出し処理手順に従って他の変数をある変数から分離し、分離された他の変数をある変数に対応するある変数として記述するものである。 In addition, the memory use method of the structure type array data of the present invention sets the area to be used for the memory, obtains the surplus area when setting the area to use a certain variable in all areas of the memory, Depending on the area of the memory, the use of other variables for the memory is permitted, the read processing procedure of the variable used for the function that is written by combining with the variable that has other variables for the memory is determined, and the read processing According to the procedure, another variable is separated from a certain variable, and the separated other variable is described as a certain variable corresponding to the certain variable.
このように本発明では、図1に示すように、構造体型の宣言1による構造体の変数を示すあるメンバ2,3,4に対して実際に使用されるデータの範囲5を示すデータ量に注目し、宣言されたメンバ2,3,4のデータ型の許容範囲(0〜31ビット)に対して実際に使用されるビット6(0〜21ビット)がどこまで使用されるのかを予め算出しておき、そのメンバの空き容量となる未使用のビット7(22〜31ビット)に他のメンバのデータ8(0〜8ビット)を割り当てることで、1つのメンバ13に対して複数のデータ9,10を共存させるものである。
As described above, in the present invention, as shown in FIG. 1, the amount of data indicating the
例えば、メンバがunsigned型である場合の構造体のデータのアクセスにおいて、メンバの最上位ビットから下位方向への一定ビットが常に未使用であることが予め分かっている場合に、処理系がビッグとリトルのどちらのエンディアンであるかにかかわらず、そのメンバの未使用ビットを同時に別のデータに割り当てることで構造体のメモリ使用量を削減することができる。
また、構造体の配列を複数の変数を用いるように宣言した場合において、構造体のメモリ使用量を削減することができる。
For example, when accessing the data of a structure when the member is an unsigned type, if it is known in advance that a certain bit from the most significant bit of the member to the lower direction is always unused, the processing system is big. Regardless of the little endian, the memory usage of the structure can be reduced by allocating unused bits of the member to different data at the same time.
Further, when the structure array is declared to use a plurality of variables, the memory usage of the structure can be reduced.
また、構造体にアクセスする場合において、メンバの未使用の上位ビットに割り当てられた特定サイズのデータAの読み出し方、また同メンバから残りのデータBの読み出し方、または、メンバの未使用の上位ビットに割り当てられた特定サイズのデータAへの書き込み方、また同メンバの残りのデータBへの書き込み方、を行う手順を決めることにより、構造体のメモリ使用量を削減するものである。 Also, when accessing a structure, how to read data A of a specific size assigned to unused upper bits of a member, how to read the remaining data B from the same member, or unused upper bits of a member The memory usage of the structure is reduced by determining the procedure for writing to the data A of a specific size assigned to the bits and writing to the remaining data B of the member.
本発明によれば、取り扱うデータ量はそのまま維持した状態でメモリ使用量を従来手法に対して削減することができる。また、共有体とは異なり複数の独立したデータを1つの記憶領域で独立して取り扱うことができ、また、ビットフィールドように処理系に依存しないため外部で定義されたデータの取り扱いも容易である。 According to the present invention, it is possible to reduce the memory usage with respect to the conventional method while maintaining the data amount to be handled as it is. In addition, unlike a shared object, a plurality of independent data can be handled independently in one storage area, and handling of externally defined data is easy because it does not depend on a processing system like a bit field. .
例えば、unsigned int型メンバとchar(もしくはunsigned char)型メンバを一まとめにした場合、その配列の数が1024個であったならばメモリ使用量を1kbyte削減することができる。unsigned int型メンバとunsigned short型メンバを一まとめにした場合は、配列の数が1024個であったらならばメモリ使用量を2kbyte削減することができる。 For example, when unsigned int type members and char (or unsigned char) type members are grouped together, if the number of arrays is 1024, the memory usage can be reduced by 1 kbyte. When unsigned int type members and unsigned short type members are grouped together, if the number of arrays is 1024, the memory usage can be reduced by 2 kbytes.
本発明は、構造体型の配列において、unsigned型データにアクセスする際に1つのメンバに複数のデータを共存させることでメモリの使用量を削減する手法に関するものである。 The present invention relates to a technique for reducing the amount of memory used by allowing a plurality of data to coexist in one member when accessing unsigned type data in a structure type array.
図2に示すように、32bitCPUの場合、構造体のメンバの型宣言をunsigned int型21とした場合、取り扱えるデータ量22は0〜4294967295であるが、実際に取り扱うデータ量23が例えば0〜16777215までであるなら、8ビットが未使用24であり空いていることになる。
As shown in FIG. 2, in the case of a 32-bit CPU, when the type declaration of a structure member is an
この空いているビットフィールド24で取り扱うことができる範囲のデータが、同じ構造体の他のメンバで使用している場合に1つのメンバで2つのデータを共存させることができる。
When data in a range that can be handled by this
本発明はunsigned型のデータに対してのみ適用されるものである。従って、他のsigned型もしくは浮動小数点型のデータに対しては適用することはできないものである。 The present invention is applied only to unsigned type data. Therefore, it cannot be applied to other signed type or floating point type data.
本発明のデータ読み出し時のフローチャートを図4に示す。同じくデータ書き込み時のフローチャートを図5に示す。またデータをパックする際のフローチャートを図6に示す。フローチャートのそれぞれの動作について説明する。 FIG. 4 shows a flowchart for reading data according to the present invention. Similarly, FIG. 5 shows a flowchart for writing data. A flowchart for packing data is shown in FIG. Each operation of the flowchart will be described.
まず、データ読み出し時には、図4において、読み出す構造体のunsigned int型のメンバをメモリからレジスタAにロードする(F1)。
次に、読み出すのはデータAかデータCかを判別する(F2)。
ここで、読み出すのがデータAであった場合、メンバの下位24bitを読み出すために、0x00FFFFFFでマスクする(F3)。
次に、マスクしたデータをレジスタBへストアする(F4)。
そして、レジスタBのデータをメモリへストアする(F5)。
First, at the time of data reading, in FIG. 4, the unsigned int type member of the structure to be read is loaded from the memory into the register A (F1).
Next, it is determined whether data A or data C is read (F2).
If the data A is read out, it is masked with 0x00FFFFFF in order to read out the lower 24 bits of the member (F3).
Next, the masked data is stored in the register B (F4).
Then, the data in the register B is stored in the memory (F5).
また、読み出すのがデータCであった場合、メンバの上位8bitを読み出すために、0xFF000000でマスクして15bit右シフトする(F6)。
次に、マスクしたデータをレジスタBへストアする(F7)。
そして、レジスタBのデータをメモリへストアする(F8)。
これで、データ読み出しを終了する(F9)。
If data C is to be read, the data is masked with 0xFF000000 and shifted to the right by 15 bits in order to read the upper 8 bits of the member (F6).
Next, the masked data is stored in the register B (F7).
Then, the data in the register B is stored in the memory (F8).
This completes the data reading (F9).
次に、データ書き込み時には、図5において、書き込む構造体のunsigned int型のメンバをメモリからレジスタAにロードする(F11)。
次に、書き込むデータをメモリからレジスタBへロードする(F12)。
書き込むはデータAかデータCかを判別する(F13)。
Next, when writing data, in FIG. 5, the unsigned int type member of the structure to be written is loaded from the memory into the register A (F11).
Next, the data to be written is loaded from the memory to the register B (F12).
It is determined whether data A or C is to be written (F13).
ここで、書き込むのがデータAであった場合、データCをバックアップのために取り出しておく(F14)。ここでは0xFF000000でマスクしたものをレジスタCにロードする。
いったん、書き込むデータを0x00FFFFFFでマスクしてレジスタAにストアする(F15)。
次に、バックアップのレジスタCのデータCをレジスタAに1bitごとの論理ORによってストアする(F16)。
そして、レジスタCのデータをメモリへストアする(F17)。
If data A is to be written, data C is taken out for backup (F14). Here, the data masked with 0xFF000000 is loaded into the register C.
Once the data to be written is masked with 0x00FFFFFF, it is stored in register A (F15).
Next, the data C of the backup register C is stored in the register A by a logical OR for each bit (F16).
Then, the data of the register C is stored in the memory (F17).
また、書き込むのがデータCであった場合、データAをバックアップのために取り出しておく(F18)。ここでは0x00FFFFFFでマスクしたものをレジスタCへロードする。
いったん、書き込むデータを0xFF000000でマスクしてレジスタAにストアする(F19)。
次に、バックアップのレジスタCのデータAをレジスタAに1bitごとの論理ORによってストアする(F20)。
そして、レジスタCのデータをメモリへストアする(F21)。
これで、データ書き込みを終了する(F22)。
If the data C is to be written, the data A is taken out for backup (F18). Here, the data masked with 0x00FFFFFF is loaded into the register C.
Once the data to be written is masked with 0xFF000000, it is stored in register A (F19).
Next, the data A of the backup register C is stored in the register A by a logical OR for each bit (F20).
Then, the data of the register C is stored in the memory (F21).
This completes the data writing (F22).
次に、データパック時には、図6において、データAとデータBをパックする構造体の該当するメンバをメモリからレジスタにロードする(F31)。
まず、パックする構造体の該当するメンバを0で初期化しておく(F32)。
次に、該当するメンバへ書き込むデータAをメモリからレジスタへロードする(F33)。
また、該当するメンバへ書き込むデータBをメモリからレジスタへロードする(F34)。
Next, at the time of data packing, in FIG. 6, the corresponding member of the structure for packing data A and data B is loaded from the memory into the register (F31).
First, the corresponding member of the structure to be packed is initialized with 0 (F32).
Next, data A to be written to the corresponding member is loaded from the memory to the register (F33).
Further, data B to be written to the corresponding member is loaded from the memory to the register (F34).
ここで、データBは予めデータAのサイズ分だけ左シフトしておき、その次にデータAとデータBを1bitごとの論理ORによってパックしてレジスタへ保持する(F35)。
そして、パックしたデータをレジスタから、該当する構造体のメンバのメモリ上の記憶領域へストアする(F36)。
上述した各処理を構造体の全ての配列にパックするまで繰り返す(F37)。
これで、データパックを終了する(F38)。
Here, the data B is shifted to the left in advance by the size of the data A, and then the data A and the data B are packed by a logical OR for each bit and held in the register (F35).
Then, the packed data is stored from the register to the storage area on the memory of the member of the corresponding structure (F36).
The above-described processes are repeated until all the structures are packed (F37).
This completes the data pack (F38).
本発明によるC言語によるプログラム例を下記に示す。下記の数5のような構造体が宣言されているとする。
A program example in C language according to the present invention is shown below. Assume that a structure like the
[数5]
typedef struct {
unsigned int data_a;
int data_b;
char data_c;
} STRUCT_DATA;
[Equation 5]
typedef struct {
unsigned int data_a;
int data_b;
char data_c;
} STRUCT_DATA;
数5は、構造体の宣言として、符号ビットのない整数型のデータaと、符号のあるデータbと、符号のあるデータcがSTRUCT_DATAの名前が付けられていることを示している。本発明では、「char data_c;」によるデータcの記述がいらなくなる。
さらに構造体が下記の数6のような配列として宣言されているとする。
Furthermore, it is assumed that the structure is declared as an array as shown in
[数6]
STRUCT_DATA tmp_data[120];
[Equation 6]
STRUCT_DATA tmp_data [120];
数6は、STRUCT_DATAの数として120ビットの実際の記憶領域を確保することを示している。
このとき、構造体のメンバdata_aには、0〜16777215までのデータ(データAと呼ぶ)をアクセスすることが事前に分かっており、また同様にdata_cには0〜100までのデータ(データCと呼ぶ)がアクセスされることが分かっているとする。このとき、図2に示すような、パック(合成)された記憶領域の読み出し/書き込み処理と、data_aにデータAとデータCを共存させるためのパック処理のプログラム例を示す。
At this time, it is known in advance that
また、図2はunsigned int型データとchar型データを共存させる際の取り扱えるデータ量を示しているが、他の場合として、図3に示すように、unsigned int型データ31とshort型/unsigned short型データ33の共存、unsigned short型データ35とchar型/unsigned char型データ37の共存などにより更なるメモリ削減効果がある。
ここで、読み出し処理時には、下記の数7のような読み出し動作を行う。
2 shows the amount of data that can be handled when unsigned int type data and char type data coexist. As shown in FIG. 3, as shown in FIG. 3, unsigned
Here, at the time of the reading process, a reading operation as shown in the following Expression 7 is performed.
[数7]
void read_data(STRUCT_DATA *s_data, short index, char size_l, char sw, unsigned int *read){
/*
*s_data :データを保持する構造体の配列を示す。
index :読み出す配列のインデックスを示す。
size_l :データA(大きい方のデータ)のサイズを示し、bit単位を示す。
sw :データA/Cの読み出し元の指定を示す。
*read :読み出したデータを保持する変数のポインタを示す。
*/
unsigned int tmp_data=0;
/* メンバの読み出し */
tmp_data = s_data[index]->data_a;
/* 読み出すデータを判別 */
/* データAを読み出す場合 */
if(sw == DATA_A){
/* データAのみをデータAのサイズに応じて読み出す*/
*read = tmp_data & (0xffffffff << size_l)~;
}
/* データCを読み出す場合 */
if(sw == DATA_C){
/* 上位byteをsize_l分右へシフトして読み出し */
*read = tmp_data >> size_l;
}
return;
}
[Equation 7]
void read_data (STRUCT_DATA * s_data, short index, char size_l, char sw, unsigned int * read) {
/ *
* s_data: An array of structures holding data.
index: Indicates the index of the array to be read.
size_l: Indicates the size of data A (larger data) and indicates the bit unit.
sw: Indicates the specification of the data A / C read source.
* read: Indicates a pointer to the variable that holds the read data.
* /
unsigned int tmp_data = 0;
/ * Read member * /
tmp_data = s_data [index]->data_a;
/ * Determine the data to read * /
/ * When reading data A * /
if (sw == DATA_A) {
/ * Read only data A according to the size of data A * /
* read = tmp_data & (0xffffffff << size_l) ~;
}
/ * When reading data C * /
if (sw == DATA_C) {
/ * Read upper byte right by size_l * /
* read = tmp_data >>size_l;
}
return;
}
数7は、STRUCT_DATAとして、ポインタのアドレスで示される合成されて記憶されているデータaとデータcを読み出す動作を示している。
次に、書き込み処理時には、下記の数8のような書き込み動作を行う。
Equation 7 shows an operation of reading the data a and the data c that are combined and stored indicated by the address of the pointer as STRUCT_DATA.
Next, at the time of the writing process, a writing operation as shown in
[数8]
void write_data(STRUCT_DATA *s_data, short index, char size_l, char sw, unsigned int write){
/*
*s_data :データを保持する構造体の配列を示す。
index :書き込む配列のインデックスを示す。
size_l :データA(大きい方のデータ)のサイズを示し、bit単位を示す。
sw :データA/Cへの書き込み先の指定を示す。
write :書き込むデータの変数を示す。
*/
unsigned int tmp_data_a, tmp_data_c = 0;
/* 書き込み先の判別 */
/* データAに書き込む場合 */
if(sw == DATA_A){
/* データCのバックアップ */
tmp_data_c = (s_data[index]->data_a) & ((0xffffffff >> size_l) << size_l);
/* 書き込むデータを一時的な変数へコピー */
tmp_data_a = write & (0xffffffff << size_l)~;
/* データCを戻す */
tmp_data_a = tmp_data_a | tmp_data_c;
}
/* データCに書き込む場合 */
if(sw == DATA_C){
/* データAのバックアップ */
tmp_data_a = (s_data[index]->data_a) & (0xffffffff << size_l)~;
/* 書き込むデータを一時的な変数へコピー */
tmp_data_c = write & ((0xffffffff >> size_l);
tmp_data_c = tmp_data_c<< size_l;
/* データAを戻す */
tmp_data_a = tmp_data_a | tmp_data_c;
}
/* データA, Cの書き込み */
s_data[index]->data_a = tmp_data_a;
return;
}
[Equation 8]
void write_data (STRUCT_DATA * s_data, short index, char size_l, char sw, unsigned int write) {
/ *
* s_data: An array of structures holding data.
index: Indicates the index of the array to be written.
size_l: Indicates the size of data A (larger data) and indicates the bit unit.
sw: Indicates the specification of the write destination to data A / C.
write: Indicates a variable of data to be written.
* /
unsigned int tmp_data_a, tmp_data_c = 0;
/ * Determine write destination * /
/ * When writing to data A * /
if (sw == DATA_A) {
/ * Backup of data C * /
tmp_data_c = (s_data [index]-> data_a) & ((0xffffffff >> size_l) <<size_l);
/ * Copy the data to write to a temporary variable * /
tmp_data_a = write & (0xffffffff << size_l) ~;
/ * Return data C * /
tmp_data_a = tmp_data_a | tmp_data_c;
}
/ * When writing to data C * /
if (sw == DATA_C) {
/ * Backup data A * /
tmp_data_a = (s_data [index]-> data_a) & (0xffffffff << size_l) ~;
/ * Copy the data to write to a temporary variable * /
tmp_data_c = write & ((0xffffffff >>size_l);
tmp_data_c = tmp_data_c <<size_l;
/ * Return data A * /
tmp_data_a = tmp_data_a | tmp_data_c;
}
/ * Write data A and C * /
s_data [index]-> data_a = tmp_data_a;
return;
}
数8は、STRUCT_DATAとして、ポインタのアドレスで示されるデータaとデータcを合成して書き込む動作を示している。
次に、パック処理時には、下記の数9のようなパック動作を行う。
Next, during the packing process, a packing operation as shown in the following equation 9 is performed.
[数9]
void pack_data(STRUCT_DATA *s_data, int count, char size_l, unsigned int *write_a, unsigned int *write_b){
/*
*s_data :データを保持する構造体の配列を示す。
counter :構造体の配列の個数を示す。
size_l :データA(大きい方のデータ)のサイズを示し、bit単位を示す。
*write_a :データAに書き込むデータの配列を示す。
*write_c :データC書き込むデータの配列を示す。
*/
unsigned int tmp_data_a, tmp_data_c = 0;
int c = 0;
/* 構造体の初期化 */
for(c = 0; c < count; c++){
s_data[c]->data_a = 0;
}
/* データAへの書き込み */
for(c = 0; c < count; c++){
/* 書き込むwrite_aを一時的な変数へコピー */
tmp_data_a = write_a[c] & (0xffffffff << size_l)~;
/* 書き込むwrite_bを一時的な変数へコピー */
tmp_data_c = write_b[c] & ((0xffffffff >> size_l);
tmp_data_c = tmp_data_c<< size_l;
/* data_a, data_cのパック */
tmp_data_a = tmp_data_a | tmp_data_c;
/* 実際の書き込み */
s_data[c]->data_a= tmp_data_a;
}
return;
}
[Equation 9]
void pack_data (STRUCT_DATA * s_data, int count, char size_l, unsigned int * write_a, unsigned int * write_b) {
/ *
* s_data: An array of structures holding data.
counter: Indicates the number of structures.
size_l: Indicates the size of data A (larger data) and indicates the bit unit.
* write_a: Indicates an array of data to be written to data A.
* write_c: Data C Data array to be written.
* /
unsigned int tmp_data_a, tmp_data_c = 0;
int c = 0;
/ * Structure initialization * /
for (c = 0; c <count; c ++) {
s_data [c]-> data_a = 0;
}
/ * Write to data A * /
for (c = 0; c <count; c ++) {
/ * Copy write_a to write to temporary variable * /
tmp_data_a = write_a [c] & (0xffffffff << size_l) ~;
/ * Copy write_b to write to temporary variable * /
tmp_data_c = write_b [c] & ((0xffffffff >>size_l);
tmp_data_c = tmp_data_c <<size_l;
/ * pack of data_a, data_c * /
tmp_data_a = tmp_data_a | tmp_data_c;
/ * Actual write * /
s_data [c]-> data_a = tmp_data_a;
}
return;
}
数9は、STRUCT_DATAとして、ポインタのアドレスで示されるデータaとデータbをパック(合成)する動作を示している。 Equation 9 shows an operation of packing (combining) data a and data b indicated by the address of the pointer as STRUCT_DATA.
図7に、構造体型配列のメモリ使用量削減装置の構成例を示す。
図7において、オーディオコーデックIC73は、メモリ使用量削減部74及びオーディオコーデック部80とを備えている。メモリ使用量削減部74は、制御手段72及びプログラム71により制御され、構造体型のあるメンバを記憶するメモリ75と、構造体型のあるメンバを使用する領域に対して他のメンバを使用する領域があるか否かを判別する判別手段76と、構造体型のあるメンバと他のメンバを読み出して保持するレジスタ77と、構造体型のあるメンバ及び他のメンバを合成する演算手段78と、合成したメンバをあるメンバとして記憶するメモリ79を備えている。
FIG. 7 shows a configuration example of a memory usage reduction device for a structure type array.
In FIG. 7, the audio codec IC 73 includes a memory usage reduction unit 74 and an
ここで、オーディオコーデック部80は、A/D変換器のダイナミックレンジが決まっているため、このダイナミックレンジ以上のビット数のオーディオデータを使用しないように構成されている。
Here, since the dynamic range of the A / D converter is determined, the
そこで、オーディオコーデック部80におけるオーディオデータのエンコード及びデコード処理においてメモリを使用する際に、メモリ使用量削減部74により、あるデータに対して未使用の領域に他のデータを使用するようにあるデータと他のデータを合成してあるデータとして処理することにより、メモリの使用量を削減することができる。
Therefore, when the memory is used in the encoding and decoding processing of the audio data in the
図8は、メモリ使用量削減部74の機能を示すブロック図である。
図8において、メモリ使用量削減部74に対して通常のC言語による記述81がされると、メモリ使用量削減部74は、まず、82に示すようにメモリに対して使用するエリアを設定し、83,84,85に示すようにメモリの全エリアにおけるある変数を使用するエリアを設定したときの余りのエリアを求める。
FIG. 8 is a block diagram illustrating functions of the memory usage reduction unit 74.
In FIG. 8, when a normal C language description 81 is given to the memory usage reduction unit 74, the memory usage reduction unit 74 first sets an area to be used for the memory as indicated by 82. 83, 84, and 85, the remaining area when an area using a certain variable in all areas of the memory is set is obtained.
次に、メモリ使用量削減部74は、86に示すように余りのエリアに応じてメモリに対して他の変数の使用を許可し、87に示すようにメモリに対して書き込まれる関数に使用される変数の書き込み処理手順を決定する。 Next, the memory usage reduction unit 74 permits the use of other variables for the memory according to the surplus area as indicated by 86 and is used for a function written to the memory as indicated by 87. Determine the variable write processing procedure.
そこで、メモリ使用量削減部74は、88に示すように書き込み処理手順に従って他の変数をある変数と合成し、89に示すように合成された変数をある変数に対応するある変数として記述する。 Therefore, the memory usage reduction unit 74 combines other variables with a certain variable in accordance with the write processing procedure as shown at 88, and describes the synthesized variable as a certain variable corresponding to the certain variable as shown at 89.
具体的には、通常のC言語による記述がされると、メモリ使用量削減部74は、自動的に上述した余りのエリア他の変数の使用可能に、他の変数をある変数と合成する処理を行って、ある変数として記述する。 Specifically, when a description is made in a normal C language, the memory usage reduction unit 74 automatically synthesizes another variable with a certain variable so that the remaining area and other variables can be used automatically. To describe as a variable.
1…構造体型の宣言、2,3,4…メンバ、5…データの範囲、宣言されたメンバ2,3,4、6…実際に使用されるビット、7…未使用のビット、8…他のメンバのデータ、9,10…複数のデータ、12…他のメンバ、13…1つのメンバ、21…unsigned int型、22…取り扱えるデータ量、23…実際に取り扱うデータ量、24…未使用8ビット、31…unsigned int型データ、33…short型/unsigned short型データ、35…unsigned short型データ、37…char型/unsigned char型データ、71…プログラム、72…制御手段、73…オーディオコーデックIC、74…メモリ使用量削減部、75…メモリ、76…判別手段、77…レジスタ、78…演算手段、79…メモリ、80…オーディオコーデック部、81…通常のC言語による記述、82…メモリに対して使用するエリアを設定、83…メモリの全エリア、84…ある変数を使用するエリアを設定、85…余りのエリア、86…他の変数の書き込み許可、87…処理手順を決定、88…他の変数をある変数と合成、89…ある変数として記述
1 ... Declaration of structure type, 2, 3, 4 ... members, 5 ... Data range, Declared
Claims (10)
上記メモリに対して使用するエリアを設定し、
上記メモリの全エリアにおけるある変数を使用するエリアを設定したときの余りのエリアを求め、
上記余りのエリアに応じて上記メモリに対して他の変数の使用を許可し、
上記メモリに対して書き込まれる関数に使用される変数の書き込み処理手順を決定し、
上記書き込み処理手順に従って上記他の変数をある変数と合成し、
上記合成された変数を上記ある変数に対応するある変数として記述する
ことを特徴とする構造体型配列のデータのメモリ使用方法。 In a method of using memory of structure type array data that uses several variables when constructing a function,
Set the area to be used for the above memory,
Find the surplus area when setting the area that uses a certain variable in all areas of the above memory,
Allow the use of other variables for the memory according to the remainder area,
Determine the procedure for writing variables used for functions written to the above memory,
Combining the other variables with a variable according to the write processing procedure,
A method of using memory of structure type array data, wherein the synthesized variable is described as a variable corresponding to the variable.
上記関数の上記ある変数は、unsigned型である
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 1,
The memory usage of the structure type array data, wherein the variable of the function is an unsigned type.
上記関数はC言語により記述されるものである
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 1,
The method for using memory of structure type array data, wherein the function is described in C language.
上記関数は使用ビット数が決められている特有のデータに適用されるものである
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 1,
The above-mentioned function is applied to specific data in which the number of bits used is determined.
上記書き込み処理手順は書き込み関数及び演算の手順である
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 1,
The method of using a memory of structure type array data, wherein the write processing procedure is a write function and a calculation procedure.
上記メモリに対して使用するエリアを設定し、
上記メモリの全エリアにおけるある変数を使用するエリアを設定したときの余りのエリアを求め、
上記余りのエリアに応じて上記メモリに対して他の変数の使用を許可し、
上記メモリに対して上記他の変数がある変数と合成して書き込まれる関数に使用される変数の読み出し処理手順を決定し、
上記読み出し処理手順に従って上記他の変数をある変数から分離し、
上記分離された上記他の変数を上記ある変数に対応するある変数として記述する
ことを特徴とする構造体型配列のデータのメモリ使用方法。 In a method of using memory of structure type array data that uses several variables when constructing a function,
Set the area to be used for the above memory,
Find the surplus area when setting the area that uses a certain variable in all areas of the above memory,
Allow the use of other variables for the memory according to the remainder area,
Determine the read processing procedure of the variable used for the function written by combining with the variable that has the other variable in the memory,
Separating the other variables from a variable according to the read processing procedure,
A method of using memory of structure type array data, wherein the separated other variable is described as a variable corresponding to the certain variable.
上記関数の上記ある変数は、unsigned型である
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 6,
The memory usage of the structure type array data, wherein the variable of the function is an unsigned type.
上記関数はC言語により記述されるものである
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 6,
The method for using memory of structure type array data, wherein the function is described in C language.
上記関数は使用ビット数が決められている特有のデータに適用されるものである
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 6,
The above-mentioned function is applied to specific data in which the number of bits used is determined.
上記読み出し処理手順は書き込み関数及び演算の手順である
ことを特徴とする構造体型配列のデータのメモリ使用方法。 The method of using memory of structure type array data according to claim 6,
The method for using a memory of structure type array data, wherein the read processing procedure is a write function and a calculation procedure.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2004163479A JP2005346272A (en) | 2004-06-01 | 2004-06-01 | Memory-using method for data of structure-type array |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2004163479A JP2005346272A (en) | 2004-06-01 | 2004-06-01 | Memory-using method for data of structure-type array |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2005346272A true JP2005346272A (en) | 2005-12-15 |
Family
ID=35498605
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2004163479A Pending JP2005346272A (en) | 2004-06-01 | 2004-06-01 | Memory-using method for data of structure-type array |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2005346272A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2017146747A (en) * | 2016-02-16 | 2017-08-24 | 日本電信電話株式会社 | Conversion method, conversion program and conversion device |
CN114047885A (en) * | 2021-11-29 | 2022-02-15 | 潍柴动力股份有限公司 | Writing method, device, equipment and medium for multi-type data |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH06230956A (en) * | 1993-02-02 | 1994-08-19 | Fujitsu Ltd | Data information editing method/device for computer programming |
JP2001290798A (en) * | 2000-04-07 | 2001-10-19 | Nintendo Co Ltd | Method and device for efficiently reading and storing vector |
-
2004
- 2004-06-01 JP JP2004163479A patent/JP2005346272A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH06230956A (en) * | 1993-02-02 | 1994-08-19 | Fujitsu Ltd | Data information editing method/device for computer programming |
JP2001290798A (en) * | 2000-04-07 | 2001-10-19 | Nintendo Co Ltd | Method and device for efficiently reading and storing vector |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2017146747A (en) * | 2016-02-16 | 2017-08-24 | 日本電信電話株式会社 | Conversion method, conversion program and conversion device |
CN114047885A (en) * | 2021-11-29 | 2022-02-15 | 潍柴动力股份有限公司 | Writing method, device, equipment and medium for multi-type data |
CN114047885B (en) * | 2021-11-29 | 2023-09-15 | 潍柴动力股份有限公司 | Method, device, equipment and medium for writing multi-type data |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP0213843A2 (en) | Digital processor control | |
US20060080485A1 (en) | Bus system and semiconductor integrated circuit | |
KR20090087689A (en) | Multi channel flash memory system and access method thereof | |
KR19990008025A (en) | Arithmetic operation system with single or double precision | |
JP3591842B2 (en) | Multiple multiport register files to accommodate different lengths of data | |
JP2005346272A (en) | Memory-using method for data of structure-type array | |
JP2005037974A (en) | Protected microprocessor equipped with system for allocating right to library | |
US5761737A (en) | Data driven type information processing apparatus having improved generation number translation | |
JP2004030224A (en) | Processor, method for retracting register and method for designating register | |
US6029210A (en) | Memory initialization system selectively outputting a data between a normal data stored in the memory and a fixed value according to a registered access state | |
JP2860655B2 (en) | Parallel instruction execution type processor | |
JP2005222519A (en) | Access to bit value in data word stored in memory | |
GB2280765A (en) | Multitasking data processing apparatus with different bus widths | |
JPH09311814A (en) | Input and output device of programmable controller | |
JPS62169205A (en) | Programmable controller | |
JP2524376B2 (en) | Instruction fetch method | |
JPS62131352A (en) | Address conversion control system | |
JP2874221B2 (en) | Arithmetic control circuit | |
JP2002032352A (en) | Multiprocessor system | |
US20040034758A1 (en) | System for producing addresses for a digital signal processor | |
JPS62209639A (en) | Memory modification writing circuit | |
JPS58201157A (en) | Control circuit of bank memory | |
JPH0219495B2 (en) | ||
JPH0784937A (en) | Microprocessor connecting circuit of peripheral circuit | |
JPS63255749A (en) | Memory system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Effective date: 20070323 Free format text: JAPANESE INTERMEDIATE CODE: A621 |
|
A977 | Report on retrieval |
Effective date: 20091214 Free format text: JAPANESE INTERMEDIATE CODE: A971007 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20100706 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20100826 |
|
A02 | Decision of refusal |
Effective date: 20110405 Free format text: JAPANESE INTERMEDIATE CODE: A02 |