source:
examples/gc_no_raii/src/internal/state.h
@
6a9d4b4
Last change on this file since 6a9d4b4 was 200fcb3, checked in by , 6 years ago | |
---|---|
|
|
File size: 1.3 KB |
Rev | Line | |
---|---|---|
[e47f529] | 1 | #pragma once |
2 | ||
[bee4283] | 3 | #ifdef __cforall |
4 | extern "C" { | |
5 | #endif | |
[e47f529] | 6 | #include <stddef.h> |
7 | #include <stdint.h> | |
[bee4283] | 8 | #ifdef __cforall |
9 | } | |
10 | #endif | |
[73abe95] | 11 | #include <fstream.hfa> |
[bee4283] | 12 | #include <vector> |
[e47f529] | 13 | |
14 | #include "tools.h" | |
[df4aea7] | 15 | |
[4ef8fb3] | 16 | typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t; |
[e47f529] | 17 | |
18 | struct 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 | ||
[4ef8fb3] | 28 | pools_table_t pools_table; |
[df4aea7] | 29 | size_t pools_table_count; |
[e47f529] | 30 | }; |
31 | ||
[16cfd8c] | 32 | void ctor(gc_state* const state); |
33 | ||
34 | void dtor(gc_state* const state); | |
[e47f529] | 35 | |
[385c130] | 36 | gc_state* gc_get_state(); |
[e47f529] | 37 | |
[16cfd8c] | 38 | static inline bool gc_needs_collect(gc_state* state) |
[e47f529] | 39 | { |
[200fcb3] | 40 | // sout | "Used Space: " | state->used_space | " bytes"; |
[e47f529] | 41 | return state->used_space * 2 > state->total_space; |
42 | } | |
43 | ||
[16cfd8c] | 44 | void gc_collect(gc_state* const this); |
[e47f529] | 45 | |
[16cfd8c] | 46 | void* gc_try_allocate(gc_state* const this, size_t size); |
[e47f529] | 47 | |
[16cfd8c] | 48 | void gc_allocate_pool(gc_state* const state); |
[e47f529] | 49 | |
[16cfd8c] | 50 | bool gc_is_in_heap(const gc_state* const state, const void* const address); |
[e47f529] | 51 | |
[16cfd8c] | 52 | bool gc_is_in_to_space(const gc_state* const state, const void* const address); |
[e47f529] | 53 | |
[16cfd8c] | 54 | static inline uint8_t gc_from_space_code(const gc_state *const this) |
[e47f529] | 55 | { |
[df4aea7] | 56 | return this->from_code; |
[e47f529] | 57 | } |
58 | ||
59 | struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*); | |
60 | ||
[16cfd8c] | 61 | static inline void gc_register_allocation(gc_state* state, size_t size) |
[e47f529] | 62 | { |
63 | state->used_space += size; | |
64 | } |
Note: See TracBrowser
for help on using the repository browser.