Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Increase max array size [duplicate]

I am trying to create an array of size 2^32 = 4294967296, because I am trying to get all the prime numbers till 2^32 by running the sieve algorithm. However any operation in that array I get the following error:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

Abort trap: 6

What can I do in above situation?

like image 493
Muhammad Raihan Muhaimin Avatar asked Apr 09 '16 22:04

Muhammad Raihan Muhaimin


1 Answers

Arrays can't be that big, the maximum length is 232-1. According to ECMAScript spec,

Every Array object has a length property whose value is always a nonnegative integer less than 232.

A String property name P is an array index if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 232−1.

like image 74
Oriol Avatar answered Oct 05 '22 23:10

Oriol