How much RAM is needed to store 1 Billion 64-bit Integers *naively* in a Java `ArrayList<Long>` (Object overhead)?
- A 8 GB
- B approximately 32 to 40 GB
- C approximately 1 TB
- D approximately 100 GB
While 1 Billion 64-bit integers should theoretically take up exactly 8 GB ($10^9 \times 8 \text{ bytes}$), storing them as objects in a high-level language like Java is much more expensive. Each `Long` object in a Java `ArrayList` carries a header (12-16 bytes), a reference from the list (4-8 bytes), and potential padding, often totaling 32-40 bytes per number. This results in a massive 4x to 5x 'memory bloat'. To solve this in production systems, engineers use 'primitive arrays' (`long[]`) or specialized libraries (like fastutil) to strip away this object overhead and return to the 8 GB baseline, which can be the difference between a single server and a costly cluster.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- What is the maximum allowed downtime per year for a system targeting '99.9%' (Three Nines) availability?
- What is the typical size of a standard ASCII character (e.g., 'A')?
- What is the typical Round Trip Time (RTT) for a single network packet traveling between New York and London (Transatlantic)?
- Network bandwidth is usually denoted in **bits** per second (Gbps), while storage is in **Bytes** (GB). What is the conversion ratio?
- Storing a password using a secure algorithm like bcrypt (cost 10) or Argon2 typically consumes how much storage per user?
- How much power does a typical fully-loaded rack-mount server consume?