-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.h
47 lines (39 loc) · 1.21 KB
/
memory.h
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//> Chunks of Bytecode memory-h
#ifndef clox_memory_h
#define clox_memory_h
//> Strings memory-include-object
#include "object.h"
//< Strings memory-include-object
//> Strings allocate
#define ALLOCATE(type, count) \
(type*)reallocate(nil, 0, sizeof(type) * (count))
//> free
#define FREE(type, pointer) \
reallocate(pointer, sizeof(type), 0)
//< free
//< Strings allocate
#define GROW_CAPACITY(capacity) \
((capacity) < 8 ? 8 : (capacity) * 2)
//> grow-array
#define GROW_ARRAY(previous, type, oldCount, count) \
(type*)reallocate(previous, sizeof(type) * (oldCount), \
sizeof(type) * (count))
//> free-array
#define FREE_ARRAY(type, pointer, oldCount) \
reallocate(pointer, sizeof(type) * (oldCount), 0)
//< free-array
void* reallocate(void* previous, usize oldSize, usize newSize);
//< grow-array
//> Garbage Collection mark-object-h
void markObject(Obj* object);
//< Garbage Collection mark-object-h
//> Garbage Collection mark-value-h
void markValue(Value value);
//< Garbage Collection mark-value-h
//> Garbage Collection collect-garbage-h
void collectGarbage(void);
//< Garbage Collection collect-garbage-h
//> Strings free-objects-h
void freeObjects(void);
//< Strings free-objects-h
#endif