v2 / vlib / v / tests / options / option_ptr_zero_test.v
28 lines · 25 sloc · 423 bytes · ef9bb8e628f3421447920d871b5f01c34af00f6b
Raw
1// Simple arena allocator
2struct ArenaChunk {
3mut:
4 next ?&ArenaChunk
5 used int
6 cap int
7 data byteptr
8}
9
10struct Arena {
11mut:
12 head ?&ArenaChunk
13}
14
15fn arena_init(mut arena Arena, first_capacity int) {
16 chunk := &ArenaChunk{
17 next: 0
18 used: 0
19 cap: first_capacity
20 data: unsafe { malloc(first_capacity) }
21 }
22 arena.head = chunk
23}
24
25fn test_main() {
26 mut green_arena := Arena{}
27 arena_init(mut green_arena, 64 * 1024)
28}
29