Erlang各種データ型で使用されるメモリサイズ
2414 ワード
erlangの言葉で言えば、erlangの異なるデータ型が占めるメモリ空間の大きさを深く理解することは、erlangの効率的なプログラミングの良い始まりです.
プログラムを実行するには、アルゴリズムを先に説明します.アルゴリズムを記述するには、アルゴリズムで使用するデータを先に説明し、データは変数または定数の形で記述されます.各変数または定数にはデータ型があります.
多くの人はアルゴリズムをどんなに上手に書くかと思って、効率的にプログラミングすると思っていますが、実はそうではありません.細かいところで工夫しています.
以下に、erlangのさまざまなデータ型に使用されるメモリサイズを示します.
Data type
Memory size
Small integer
1 wordOn 32-bit architectures: -134217729 < i < 134217728 (28 bits)On 64-bit architectures: -576460752303423489 < i < 576460752303423488 (60 bits)
Big integer
3..N words
Atom
1 word. Note: an atom refers into an atom table which also consumes memory. The atom text is stored once for each unique atom in this table. The atom table is not garbage-collected.
Float
On 32-bit architectures: 4 words On 64-bit architectures: 3 words
Binary
3..6 + data (can be shared)
List
1 word + 1 word per element + the size of each element
String (is the same as a list of integers)
1 word + 2 words per character
Tuple
2 words + the size of each element
Pid
1 word for a process identifier from the current local node, and 5 words for a process identifier from another node. Note: a process identifier refers into a process table and a node table which also consumes memory.
Port
1 word for a port identifier from the current local node, and 5 words for a port identifier from another node. Note: a port identifier refers into a port table and a node table which also consumes memory.
Reference
On 32-bit architectures: 5 words for a reference from the current local node, and 7 words for a reference from another node. On 64-bit architectures: 4 words for a reference from the current local node, and 6 words for a reference from another node. Note: a reference refers into a node table which also consumes memory.
Fun
9..13 words + size of environment. Note: a fun refers into a fun table which also consumes memory.
Ets table
Initially 768 words + the size of each element (6 words + size of Erlang data). The table will grow when necessary.
Erlang process
327 words when spawned including a heap of 233 words.
では、1つのwordはどのくらいの空間を占めていますか?
参照先:http://blog.csdn.net/mycwq/article/details/16893209
プログラムを実行するには、アルゴリズムを先に説明します.アルゴリズムを記述するには、アルゴリズムで使用するデータを先に説明し、データは変数または定数の形で記述されます.各変数または定数にはデータ型があります.
多くの人はアルゴリズムをどんなに上手に書くかと思って、効率的にプログラミングすると思っていますが、実はそうではありません.細かいところで工夫しています.
以下に、erlangのさまざまなデータ型に使用されるメモリサイズを示します.
Data type
Memory size
Small integer
1 wordOn 32-bit architectures: -134217729 < i < 134217728 (28 bits)On 64-bit architectures: -576460752303423489 < i < 576460752303423488 (60 bits)
Big integer
3..N words
Atom
1 word. Note: an atom refers into an atom table which also consumes memory. The atom text is stored once for each unique atom in this table. The atom table is not garbage-collected.
Float
On 32-bit architectures: 4 words On 64-bit architectures: 3 words
Binary
3..6 + data (can be shared)
List
1 word + 1 word per element + the size of each element
String (is the same as a list of integers)
1 word + 2 words per character
Tuple
2 words + the size of each element
Pid
1 word for a process identifier from the current local node, and 5 words for a process identifier from another node. Note: a process identifier refers into a process table and a node table which also consumes memory.
Port
1 word for a port identifier from the current local node, and 5 words for a port identifier from another node. Note: a port identifier refers into a port table and a node table which also consumes memory.
Reference
On 32-bit architectures: 5 words for a reference from the current local node, and 7 words for a reference from another node. On 64-bit architectures: 4 words for a reference from the current local node, and 6 words for a reference from another node. Note: a reference refers into a node table which also consumes memory.
Fun
9..13 words + size of environment. Note: a fun refers into a fun table which also consumes memory.
Ets table
Initially 768 words + the size of each element (6 words + size of Erlang data). The table will grow when necessary.
Erlang process
327 words when spawned including a heap of 233 words.
では、1つのwordはどのくらいの空間を占めていますか?
1> erlang:system_info(wordsize).
8
は、通常、32ビットシステムが4バイト、64ビットシステムが8バイトを占める.参照先:http://blog.csdn.net/mycwq/article/details/16893209