Skip to content

Commit 4b7f255

Browse files
authored
Create memory.h
1 parent ac536d7 commit 4b7f255

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

memory.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef MEMORY_H
2+
#define MEMORY_H
3+
4+
#include <stddef.h>
5+
6+
#define GROW_CAPACITY(capacity) \
7+
((capacity) < 8 ? 8 : (capacity) * 2)
8+
9+
#define GROW_ARRAY(type, pointer, oldCount, newCount) \
10+
(type*)reallocate(pointer, sizeof(type) * (oldCount), \
11+
sizeof(type) * (newCount))
12+
13+
#define FREE_ARRAY(type, pointer, oldCount) \
14+
reallocate(pointer, sizeof(type) * (oldCount), 0)
15+
16+
#define ALLOCATE(type, count) \
17+
(type*)reallocate(NULL, 0, sizeof(type) * (count))
18+
19+
#define FREE(type, pointer) reallocate(pointer, sizeof(type), 0)
20+
21+
#endif

0 commit comments

Comments
 (0)