Changes in / [3b8e52c:7a5d773]
- Location:
- src/examples/gc_no_raii
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/gc_no_raii/premake4.lua
r3b8e52c r7a5d773 6 6 "src/", 7 7 "../", 8 "containers/" 8 9 } 9 10 … … 48 49 linkoptions (linkOptionList) 49 50 includedirs (includeDirList) 50 files { "src/**.c" }51 files { "src/**.c", "containers/**.c" } 51 52 52 53 configuration "debug" -
src/examples/gc_no_raii/src/gc.h
r3b8e52c r7a5d773 4 4 #include "internal/collector.h" 5 5 6 forall(otype T)7 static inline gcpointer(T) gcmalloc()8 {9 gcpointer(T) ptr = { gc_allocate(sizeof(T)) };10 ptr{};11 gc_conditional_collect();12 return ptr;13 }6 // forall(otype T) 7 // static inline gcpointer(T) gcmalloc() 8 // { 9 // gcpointer(T) ptr = { gc_allocate(sizeof(T)) }; 10 // ptr{}; 11 // gc_conditional_collect(); 12 // return ptr; 13 // } 14 14 15 15 forall(otype T) 16 16 static inline void gcmalloc(gcpointer(T)* ptr) 17 17 { 18 ptr { gc_allocate(sizeof(T)) };19 (*ptr){};18 ptr { gc_allocate(sizeof(T)) }; 19 get(ptr) {}; 20 20 gc_conditional_collect(); 21 21 } -
src/examples/gc_no_raii/src/gcpointers.c
r3b8e52c r7a5d773 42 42 } 43 43 44 void gcpointer_ctor(gcpointer_t* this)44 void ?{}(gcpointer_t* this) 45 45 { 46 46 this->ptr = (intptr_t)NULL; … … 48 48 } 49 49 50 void gcpointer_ctor(gcpointer_t* this, void* address)50 void ?{}(gcpointer_t* this, void* address) 51 51 { 52 52 this->ptr = (intptr_t)address; … … 56 56 } 57 57 58 void gcpointer_ctor(gcpointer_t* this, gcpointer_t*other)58 void ?{}(gcpointer_t* this, gcpointer_t other) 59 59 { 60 this->ptr = other ->ptr;60 this->ptr = other.ptr; 61 61 this->next = NULL; 62 62 … … 64 64 } 65 65 66 void gcpointer_dtor(gcpointer_t* this)66 void ^?{}(gcpointer_t* this) 67 67 { 68 68 unregister_ptr(this); … … 98 98 return this->ptr == (intptr_t)NULL; 99 99 } 100 101 forall(otype T) void ?{}(gcpointer(T)* this) { 102 (&this->internal) {}; 103 } 104 105 forall(otype T) void ?{}(gcpointer(T)* this, void* address) { 106 (&this->internal) { address }; 107 } 108 109 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other) { 110 (&this->internal) { other->internal }; 111 } 112 113 forall(otype T) void ^?{}(gcpointer(T)* this) { 114 ^?{}(&this->internal); 115 } 116 117 // forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs); 118 // 119 // forall(otype T) T *?(gcpointer(T) this); 120 121 forall(otype T) T* get(gcpointer(T)* this) { 122 return (T*)this->internal.ptr; 123 } 124 // 125 // //Logical operators 126 // forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs); 127 // forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs); -
src/examples/gc_no_raii/src/gcpointers.h
r3b8e52c r7a5d773 30 30 forall(otype T) void ?{}(gcpointer(T)* this); 31 31 forall(otype T) void ?{}(gcpointer(T)* this, void* address); 32 forall(otype T) void ctor(gcpointer(T)* this, void* address);33 32 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other); 34 33 forall(otype T) void ^?{}(gcpointer(T)* this); … … 37 36 38 37 forall(otype T) T *?(gcpointer(T) this); 38 forall(otype T) T* get(gcpointer(T)* this); 39 39 40 40 //Logical operators -
src/examples/gc_no_raii/src/internal/collector.c
r3b8e52c r7a5d773 8 8 } 9 9 #endif 10 11 #include <fstream> 10 12 11 13 #include "state.h" … … 36 38 void* gc_allocate(size_t target_size) 37 39 { 40 sout | "Allocating " | target_size | " bytes" | endl; 41 38 42 size_t size = gc_compute_size(target_size + sizeof(gc_object_header)); 43 44 sout | "Object header size: " | sizeof(gc_object_header) | " bytes" | endl; 45 sout | "Actual allocation size: " | size | " bytes" | endl; 39 46 40 47 check(size < POOL_SIZE_BYTES); -
src/examples/gc_no_raii/src/internal/state.h
r3b8e52c r7a5d773 9 9 } 10 10 #endif 11 #include <fstream> 11 12 #include <vector> 12 13 … … 37 38 static inline bool gc_needs_collect(gc_state* state) 38 39 { 40 sout | "Used Space: " | state->used_space | " bytes" | endl; 39 41 return state->used_space * 2 > state->total_space; 40 42 } -
src/examples/gc_no_raii/test/gctest.c
r3b8e52c r7a5d773 2 2 3 3 #include "gc.h" 4 #include "internal/collector.h" 4 5 5 6 #warning default test … … 8 9 sout | "Bonjour au monde!\n"; 9 10 10 for(int i = 0; i < 1000000; i++) { 11 gcpointer(int) anInt; 12 gcmalloc(&anInt); 11 gcpointer(int) theInt; 12 gcmalloc(&theInt); 13 14 for(int i = 0; i < 10; i++) { 15 int a; 16 { 17 gcpointer(int) anInt; 18 gcmalloc(&anInt); 19 } 20 int p; 13 21 } 22 23 gc_collect(gc_get_state()); 24 gc_conditional_collect(); 14 25 }
Note: See TracChangeset
for help on using the changeset viewer.