erlang 各种数据类型占用的内存大小
2013-12-03 20:51
459 查看
用erlang的话讲,深入了解erlang不同数据类型所占的内存空间大小,是erlang高效编程的一个良好开始。
一个程序要运行,就要先描述其算法。描述一个算法应先说明算法中要用的数据,数据以变量或常量的形式来描述。每个变量或常量都有数据类型。
很多人都以为要把算法写得多精湛,才算高效编程,其实不然,细微处见功夫。
以下内容展示了erlang各种数据类型占用的内存大小。
那么,一个word占多大的空间?
1> erlang:system_info(wordsize).
8通常情况下,32位系统占4字节,64位系统占8字节。
参考:http://blog.csdn.net/mycwq/article/details/16893209
一个程序要运行,就要先描述其算法。描述一个算法应先说明算法中要用的数据,数据以变量或常量的形式来描述。每个变量或常量都有数据类型。
很多人都以为要把算法写得多精湛,才算高效编程,其实不然,细微处见功夫。
以下内容展示了erlang各种数据类型占用的内存大小。
Data type | Memory size |
Small integer | 1 word On 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> erlang:system_info(wordsize).
8通常情况下,32位系统占4字节,64位系统占8字节。
参考:http://blog.csdn.net/mycwq/article/details/16893209
相关文章推荐
- 浅说数据类型占用的内存大小
- C/C++中不同数据类型所占用的内存大小
- python 基本数据类型占用内存空间大小的实例
- C/C++中不同数据类型所占用的内存大小
- JAVA基本数据类型占用内存大小
- c++拾遗之数据类型占用内存大小总结
- python 基本数据类型占用内存空间大小
- java中的各种数据类型在内存中存储的方式
- 16位,32位,64位下各种数据类型的长度大小
- java中的各种数据类型在内存中存储的方式
- java基本数据类型及其默认内存占用
- 【转】【C++】【MFC】各种数据类型大小
- java中的各种数据类型在内存中存储的方式
- 各种语言数据类型大小
- 指针(内存大小和数据类型无关,和系统操作位数有关),对象,地址,和系统操作位数的关系
- python 之 不同类型对象的内存占用、大小比较
- java中的各种数据类型在内存中的存储
- C++ 基本语法之变量(指针)与数据类型(占用字节大小)
- java中的各种数据类型在内存中存储的方式
- 关于操作系统各种数据类型的内存分配的一点探讨