Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/test_2GB_fail.cpp
4150 views
1
#include <assert.h>
2
#include <emscripten.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
6
void* allocation;
7
8
int main() {
9
const int CHUNK_SIZE = 100 * 1024 * 1024;
10
const int NUM_CHUNKS = 31; // total allocation will be over 3GB
11
12
puts("allocating");
13
14
for (int i = 0; i < NUM_CHUNKS; i++) {
15
printf("alloc %d\n", i);
16
allocation = malloc(CHUNK_SIZE);
17
if (!allocation) {
18
assert(i <= 20); // can't get to 2GB
19
puts("expected allocation failure");
20
return 0;
21
}
22
}
23
24
puts("UNEXPECTED");
25
}
26
27