Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/test_4GB.cpp
4150 views
1
#include <assert.h>
2
#include <emscripten.h>
3
#include <stdio.h>
4
#include <vector>
5
6
int main() {
7
const int CHUNK_SIZE = 100 * 1024 * 1024;
8
const int NUM_CHUNKS = 31; // total allocation will be over 3GB
9
10
std::vector<std::vector<char>> chunks;
11
chunks.resize(NUM_CHUNKS);
12
13
puts("allocating");
14
15
for (int i = 0; i < NUM_CHUNKS; i++) {
16
printf("alloc %d\n", i);
17
chunks[i].resize(CHUNK_SIZE);
18
}
19
20
puts("testing");
21
22
for (int i = 0; i < NUM_CHUNKS; i++) {
23
printf("test %d\n", i);
24
chunks[i][i] = i;
25
int fromJS = EM_ASM_INT({
26
return HEAP8[$0];
27
}, &chunks[i][i]);
28
printf("wrote %d in C, read %d from JS\n", i, fromJS);
29
EM_ASM_INT({
30
HEAP8[$0] = 2 * $1;
31
}, &chunks[i][i], i);
32
int fromC = chunks[i][i];
33
printf("wrote %d in JS, read %d from C\n", 2 * i, fromC);
34
}
35
36
puts("success");
37
}
38
39
40