source: examples/gc_no_raii/src/internal/state.h @ 2773ab8

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2773ab8 was 200fcb3, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

add auto newline to sout, change endl to nl

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#pragma once
2
3#ifdef __cforall
4extern "C" {
5#endif
6#include <stddef.h>
7#include <stdint.h>
8#ifdef __cforall
9}
10#endif
11#include <fstream.hfa>
12#include <vector>
13
14#include "tools.h"
15
16typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
17
18struct gc_state
19{
20        bool is_initialized;
21        uint8_t from_code;
22        struct gc_memory_pool* to_space;
23        struct gc_memory_pool* from_space;
24
25        size_t total_space;
26        size_t used_space;
27
28        pools_table_t   pools_table;
29        size_t          pools_table_count;
30};
31
32void ctor(gc_state* const state);
33
34void dtor(gc_state* const state);
35
36gc_state* gc_get_state();
37
38static inline bool gc_needs_collect(gc_state* state)
39{
40        // sout | "Used Space: " | state->used_space | " bytes";
41        return state->used_space * 2 > state->total_space;
42}
43
44void gc_collect(gc_state* const this);
45
46void* gc_try_allocate(gc_state* const this, size_t size);
47
48void gc_allocate_pool(gc_state* const state);
49
50bool gc_is_in_heap(const gc_state* const state, const void* const address);
51
52bool gc_is_in_to_space(const gc_state* const state, const void* const address);
53
54static inline uint8_t gc_from_space_code(const gc_state *const this)
55{
56        return this->from_code;
57}
58
59struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
60
61static inline void gc_register_allocation(gc_state* state, size_t size)
62{
63        state->used_space += size;
64}
Note: See TracBrowser for help on using the repository browser.