diff options
Diffstat (limited to 'test_arena.cpp')
-rwxr-xr-x | test_arena.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test_arena.cpp b/test_arena.cpp new file mode 100755 index 0000000..545e4ba --- /dev/null +++ b/test_arena.cpp @@ -0,0 +1,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;
+}
|