-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory.h
40 lines (29 loc) · 1.27 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
#ifndef clox_memory_h
#define clox_memory_h
#include "object.h"
#define DBG_GC_GENERAL 1 // log begin/end of GC and trigger from alloc
#define DBG_GC_ALLOC 2 // log allocation of an object
#define DBG_GC_FREE 4 // log de-allocation of an object
#define DBG_GC_MARK 8 // log each object marked during GC
#define DBG_GC_BLACK 16 // log each object blackened during GC
#define DBG_GC_STRINGS 32 // log shrinking of strings table
#define DBG_GC_STRESS 64 // force GC before each allocation
#define ALLOCATE(type, count) \
(type*)reallocate(NULL, 0, sizeof(type) * (count))
#define FREE(type, pointer) \
reallocate(pointer, sizeof(type), 0)
#define GROW_CAPACITY(capacity) \
((capacity) < 4 ? 4 : (capacity) * 2)
#define MIN_LIST_CAPACITY(len) \
((len) < 8 ? 8 : (len))
#define GROW_ARRAY(type, pointer, oldCount, newCount) \
(type*)reallocate(pointer, sizeof(type) * (oldCount), sizeof(type) * (newCount))
#define FREE_ARRAY(type, pointer, oldCount) \
(type*)reallocate(pointer, sizeof(type) * (oldCount), 0)
void* reallocate(void* pointer, size_t oldSize, size_t newSize);
void markObject(Obj* object);
void markValue(Value value);
void collectGarbage(bool checkReclaim);
void freeObjects(void);
extern char big_buffer[INPUT_SIZE];
#endif