[Haskell-cafe] Sizes in memory?
Dušan Kolář
kolar at fit.vut.cz
Fri Feb 19 08:05:04 UTC 2021
Dear café,
I don't know, whether this is the right place to ask, but I'll try :-)
If I would like to know size of the list in the memory (after complete evaluation, e.g.
deepseq). The type is [( Int, [([Int],[Int])] )].
So we have K tuples of the type (Int,[([Int],[Int])])
Each tuple has N tuples of the type ([Int],[Int])
and each of these lists M elements long (yes, both a are of the same length).
Top level list needs (on 64bit CPU) 8 bytes for pointer to elements, 8 bytes to point
to another element, some more "expenses", probably yes, tag, anything else?
So we have K*(16+XXX), where XXX is for size of (Int,[([Int],[Int])]).
Tuple needs 8 bytes for each pointer, so XXX = 16 + YYY, where YYY is the size of the
[([Int],[Int])] list. It needs 8 + 8 bytes on the list, we have N such elements, thus YYY =
N * (16 + ZZZ), where ZZZ is size of the ([Int],[Int]).
Again tuple, so 16 bytes + 2*(M * (16 + 8))
-- 16 bytes for 2 tuple elements
-- 2 for two lists
-- every list 16 bytes for list itself
-- 8 bytes for Int
So ZZZ = 16 + 2*(M * (16 + 8)), thus
YYY = N * (16 + 16 + 2*(M * (16 + 8))), thus
XXX = 16 + N * (16 + 16 + 2*(M * (16 + 8))), thus
size = K * (16 + 16 + N * (16 + 16 + 2*(M * (16 + 8))))
= K* (32 + N* (32 + M*48) )
Am I right? Roughly right? Or totally wrong?
E.g. for K = 25, N = 10000, M = 7 we get cca 88MiB ?
Why am I asking? In reality the memory consumption is much higher, so I must be
missing some extras, e.g. each memory chunk extra 8 bytes for GC, extra for tag,
extra to point to VMT?
Regards,
Dušan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210219/db5c9215/attachment.html>
More information about the Haskell-Cafe
mailing list