-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgc.h
More file actions
26 lines (22 loc) · 760 Bytes
/
gc.h
File metadata and controls
26 lines (22 loc) · 760 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
#pragma once
struct gc_state;
void* gc_new(struct gc_state* gc, size_t size);
void* gc_new0(struct gc_state* gc, size_t size);
void gc_free(struct gc_state* gc, void* obj);
void gc_collect(struct gc_state* gc);
void gc_add_root(struct gc_state* gc, void* obj);
void gc_register_module(struct gc_state* gc, /* HMODULE */ void* hModule);
size_t gc_get_object_count(struct gc_state* gc);
struct gc_state* gc_create();
#ifdef __cplusplus
#include <type_traits>
#include <new>
template<typename T, typename... Args>
T* gc_make(gc_state* gc, Args&&... args)
{
static_assert(std::is_trivially_destructible<T>::value, "T must be trivially destructible");
T* value = (T*)gc_new(gc, sizeof(T));
new (value) T(std::forward<Args>(args)...);
return value;
}
#endif