Last active
November 5, 2015 04:50
-
-
Save vicapow/ee9f5f8180b39b438072 to your computer and use it in GitHub Desktop.
Was I really just able to allocate 56GB of memory in Google chrome?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x = []; | |
for (var i = 0; i < 56; i++) { | |
x.push(new Uint8Array(1024 * 1024 * 1024)); | |
} | |
console.log(x.length); |
It's not until you start accessing that memory that it really gets mapped in by the system, so on a 64bit OS you can "allocate" huge amounts but you can't use it all, since your machine will reach some limit before it gets all used up and mapped in. But there is some room for jokes on browser memory consumption here. =)
@icepic are you saying this is happening by the browser? Or at the OS level? https://twitter.com/vicapow/status/655248145316642816?s=17
Here, I allocate 50GB, assign each byte a random value [0, 256)
and accumulate the result. One downside, as far as I can tell, you can't allocate a single TypedArray larger than 1GB.
This took ~23min to run but didn't crash!
var t0 = Date.now();
var x = [];
var GB1 = 1024 * 1024 * 1024;
var i;
var j;
var gigs = 50;
for (i = 0; i < gigs; i++) {
x.push(new Uint8Array(GB1));
for (j = 0; j < GB1; j++) {
x[i][j] = Math.random() * 256 | 0;
}
console.log('gig', i);
console.log('t', Date.now() - t0);
}
i = 0;
var accum = 0;
for (i = 0; i < gigs; i++) {
for(j = 0; j < GB1; j++) {
accum = accum + x[i][j] - 128;
}
console.log('gig', i);
console.log('t', Date.now() - t0);
}
console.log('accum', accum);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can confirm it works.