Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(The following applies to GHC, other compilers may use different storage conventions)</p> <p>Rule of thumb: <strong>a constructor costs one word for a header, and one word for each field</strong>. Exception: a constructor with no fields (like <code>Nothing</code> or <code>True</code>) takes no space, because GHC creates a single instance of these constructors and shares it amongst all uses.</p> <p>A word is 4 bytes on a 32-bit machine, and 8 bytes on a 64-bit machine.</p> <p>So e.g. </p> <pre><code>data Uno = Uno a data Due = Due a b </code></pre> <p>an <code>Uno</code> takes 2 words, and a <code>Due</code> takes 3.</p> <p>The <code>Int</code> type is defined as</p> <pre><code>data Int = I# Int# </code></pre> <p>now, <code>Int#</code> takes one word, so <code>Int</code> takes 2 in total. Most unboxed types take one word, the exceptions being <code>Int64#</code>, <code>Word64#</code>, and <code>Double#</code> (on a 32-bit machine) which take 2. GHC actually has a cache of small values of type <code>Int</code> and <code>Char</code>, so in many cases these take no heap space at all. A <code>String</code> only requires space for the list cells, unless you use <code>Char</code>s > 255.</p> <p>An <code>Int8</code> has identical representation to <code>Int</code>. <code>Integer</code> is defined like this:</p> <pre><code>data Integer = S# Int# -- small integers | J# Int# ByteArray# -- large integers </code></pre> <p>so a small <code>Integer</code> (<code>S#</code>) takes 2 words, but a large integer takes a variable amount of space depending on its value. A <code>ByteArray#</code> takes 2 words (header + size) plus space for the array itself.</p> <p>Note that <strong>a constructor defined with <code>newtype</code> is free</strong>. <code>newtype</code> is purely a compile-time idea, and it takes up no space and costs no instructions at run time.</p> <p>More details in <a href="http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/HeapObjects" rel="noreferrer">The Layout of Heap Objects in the GHC Commentary</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload