For a sieve algorithm, you need just one bit for each number to test...
Look for a bitset implementation (https://github.com/tdegrunt/bitset for instance).
This one will grow dynamically as you set bits in it. You can set and get bits, and each bit will tell you if n
is a prime.
However, I recommend you test with max 100, not 2^32... because it will be slow...
Actually, bitset breaks between 10M and 100M on my Mac. I guess they don't use a byte array.
In coffee-script because it's less verbose...
Bitset = require 'bitset'
sieve = (maxSize)=>
mark = (bitset)->
markMultiplesOf = (n)->
bitset.set(n*each) for each in [2..(maxSize / n)]
markMultiplesOf each for each in [2..(maxSize / 2)] when bitset.get(each) is false
showPrimes = (bitset)->
console.log each for each in [0..(bitset.length())] when bitset.get(each) is false
timestamp = Date.now()
bitset = new Bitset(maxSize)
mark bitset, maxSize
console.log "took #{Date.now() - timestamp} ms"
showPrimes(bitset)
sieve(10000000) # takes < 4s