TL; DR:
The ETS table allocates memory size in bytes:
ets:info(Table,memory) * erlang:system_info(wordsize).
To develop a bit, ets:info(Table,memory) gives you the words allocated for the data in the ETS table (the same for Mnesia. You can view this information in the TV application. The same attribute for the DETS tables is in bytes).
A word is nothing more than a “natural” block of data for a specific CPU architecture. What represents depends on your architecture: 32-bit or 64-bit (or use erlang:system_info(wordsize) to get the right word size immediately)
- On a 32-bit system, a word is 4 bytes (32 bits).
- On a system, a 64-bit word is 8 bytes (64 bits).
Also note that the ETS table initially covers 768 words , to which you must add the size of each element, 6 words + size Erlang data. It is not clear whether these words are "allocated for data" ets:info .
Calculating the exact size is a bit of a hassle: ETS tables have their own independent memory management system, which is optimized and garbage collected, and may vary depending on the type of table ( set , bag , duplicate_bag ). As an experiment, an empty table in my environment returns 300 words “allocated to data”. If you add 11 tuples, the size increases to 366 words. There is no idea how they relate to the original 768 words, or why the size only increases by 11 * 6 words, when it was supposed to be 11 * 6 + 11 * 1 (11 atoms), as defined.
However, a naive estimate taking the initial size of the table and the words allocated for the data, for example 22086 words, leads to 768 * 8 + 22.086 * 8 = 182.832 bytes (178.54 KiB).
Of course, the more data, the less "structural" words matter, so you can only use the number of "words allocated for data" that ets:info returns to estimate the size of your table in memory.
Change There are two other functions that allow you to check the use of ETS memory:
erlang:memory/1 : erlang:memory(ets) returns the byte memory size assigned by ETS.ets:i/0 : overview of all active ETS tables (a bit like viewing system tables on TV , but with type and memory data).
As a small test, the newly created empty table increased memory usage with 312 words (2.44 KiB), which is much less than the number 768 in the manual (perhaps this is due to the processor architecture, I have no idea), while the ETS itself reported 299 words (2.33 KiB) allocated for the data.
This is only 13 words (104 bytes) of structural overhead (or seems to be foggy) from the erlang:memory/1 message, so ets:info/2 is pretty accurate after all.
After entering a simple tuple of 2 atoms, erlang:memory/1 reported an increase in memory allocation of 8 words, as in the documentation mentioned (new ETS record: 6 words + data size - 2 in this case: 1 word per atom).