-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.h
More file actions
31 lines (23 loc) · 933 Bytes
/
Copy pathmemory.h
File metadata and controls
31 lines (23 loc) · 933 Bytes
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
#ifndef PL_MEMORY_H
#define PL_MEMORY_H
#include "common.h"
#include "object.h"
// We used reallocate everywhere,
// because later it will be convenient to keep track of uncleared memory
#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) < 8 ? 8 : capacity * 2)
#define GROW_ARRAY(type, pointer, old_size, new_size) \
(type*)reallocate(pointer, sizeof(type) * (old_size), \
sizeof(type) * (new_size))
#define FREE_ARRAY(type, pointer, old_size) \
reallocate(pointer, sizeof(type) * (old_size), 0)
// This function take care of allocating, freeing memory and changing the size
void *reallocate(void *pointer, size_t old_size, size_t new_size);
void mark_object(Obj *object);
void mark_value(Value value);
void collect_garbage();
void free_objects();
#endif // PL_MEMORY_H