blob: 545e4bae2cb02017c44a0546793387b2586d32f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include "dynarray.h"
DECL_MAIN {
// Reserving 16GiB.
auto a = Arena(16ULL * 1024ULL * 1024ULL * 1024ULL);
// Committing 1MiB to make space for 4 bytes (with some headroom).
bool committed = a.Grow(4);
assert(committed);
a.base[0] = 'a';
a.base[1] = 'b';
a.base[2] = 'c';
a.base[4] = '\0';
std::cout << a.base << std::endl;
// Past the declared length, but still in committed memory.
// No segfault, but in real code it's probably a bug.
a.base[5] = 'x';
a.base[kBytesPerCommit-1] = 'y';
// Reserved, but not committed memory. Segfault.
// a.base[kBytesPerCommit] = 'x';
return 0;
}
|