title: Python: How much space does each element of a list take?
body: <p>I need a very large list, and am trying to figure out how big I can make it so that it still fits in 1-2GB of RAM. I am using the CPython implementation, on 64 bit (x86_64).</p>
  
  <p><em>Edit: thanks to bua's answer, I have filled in some of the more concrete answers.</em></p>
  
  <p>What is the space (memory) usage of (in bytes):</p>
  
  <ul>
  <li>the list itself
  
  <ul>
  <li><code>sys.getsizeof([]) == 72</code></li>
  </ul></li>
  <li>each list entry (not including the data)
  
  <ul>
  <li><code>sys.getsizeof([0, 1, 2, 3]) == 104</code>, so 8 bytes overhead per entry.</li>
  </ul></li>
  <li>the data if it is an integer
  
  <ul>
  <li><code>sys.getsizeof(2**62) == 24</code> (but varies according to integer size)</li>
  <li><code>sys.getsizeof(2**63) == 40</code></li>
  <li><code>sys.getsizeof(2**128) == 48</code></li>
  <li><code>sys.getsizeof(2**256) == 66</code></li>
  </ul></li>
  <li>the data if it is an object (<code>sizeof(Pyobject)</code> I guess))
  
  <ul>
  <li><code>sys.getsizeof(C()) == 72</code> (C is an empty user-space object)</li>
  </ul></li>
  </ul>
  
  <p>If you can share more general data about the observed sizes, that would be great. For example:</p>
  
  <ul>
  <li>Are there special cases (I think immutable values might be shared, so maybe a list of bools doesn't take any extra space for the data)?</li>
  <li>Perhaps small lists take X bytes overhead but large lists take Y bytes overhead?</li>
  </ul>