How many integers can I create in 1 GB of memory?

Robert Sedgewick’s fourth edition of Book Algorithms on page 200 says: “For example, if you have 1 GB of memory on your computer (1 billion bytes), you cannot store more than 32 million int values.”

I was confused after my calculations: 1,000,000,000 bytes / 4 bytes = 250 million

How did the author get 32 ​​million?

The book describes as shown below:

enter image description here

+5
source share
2 answers

The author acknowledged that this is a mistake on this website of the book, please refer to the following link: http://algs4.cs.princeton.edu/errata/errata-printing3.php

+4
source

1 gigabit = 1073741824 bit
1 int = 32 bits
calculation = (1073741824/32) = (32 * 1024 2 ) = (32 * 2 20 ) = 32 million

If the author meant giga bytes , then the answer would be (32 * 8) million = 256 million

+2
source

Source: https://habr.com/ru/post/1243566/


All Articles