<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Dear café,</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">I don't know, whether this is the right place to ask, but I'll try :-)</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">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])] )].</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">So we have K tuples of the type (Int,[([Int],[Int])])</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Each tuple has N tuples of the type ([Int],[Int])</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">and each of these lists M elements long (yes, both a are of the same length).</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">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?</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">So we have K*(16+XXX), where XXX is for size of (Int,[([Int],[Int])]).</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">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]).</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Again tuple, so 16 bytes + 2*(M * (16 + 8))</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">-- 16 bytes for 2 tuple elements</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">-- 2 for two lists</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">-- every list 16 bytes for list itself</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">-- 8 bytes for Int</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">So ZZZ = 16 + 2*(M * (16 + 8)), thus</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">YYY = N * (16 + 16 + 2*(M * (16 + 8))), thus</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">XXX = 16 + N * (16 + 16 + 2*(M * (16 + 8))), thus</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">size = K * (16 + 16 + N * (16 + 16 + 2*(M * (16 + 8))))</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">     = K* (32 + N* (32 + M*48) )</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Am I right? Roughly right? Or totally wrong?</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">E.g. for K = 25, N = 10000, M = 7 we get cca 88MiB ? </p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">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?</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Regards,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Dušan</p>
<br /></body>
</html>