Changes in / [7a5d773:3b8e52c]
- Location:
- src/examples/gc_no_raii
- Files:
-
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/gc_no_raii/premake4.lua
r7a5d773 r3b8e52c 6 6 "src/", 7 7 "../", 8 "containers/"9 8 } 10 9 … … 49 48 linkoptions (linkOptionList) 50 49 includedirs (includeDirList) 51 files { "src/**.c" , "containers/**.c"}50 files { "src/**.c" } 52 51 53 52 configuration "debug" -
src/examples/gc_no_raii/src/gc.h
r7a5d773 r3b8e52c 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 19 get(ptr){};18 ptr{ gc_allocate(sizeof(T)) }; 19 (*ptr){}; 20 20 gc_conditional_collect(); 21 21 } -
src/examples/gc_no_raii/src/gcpointers.c
r7a5d773 r3b8e52c 42 42 } 43 43 44 void ?{}(gcpointer_t* this)44 void gcpointer_ctor(gcpointer_t* this) 45 45 { 46 46 this->ptr = (intptr_t)NULL; … … 48 48 } 49 49 50 void ?{}(gcpointer_t* this, void* address)50 void gcpointer_ctor(gcpointer_t* this, void* address) 51 51 { 52 52 this->ptr = (intptr_t)address; … … 56 56 } 57 57 58 void ?{}(gcpointer_t* this, gcpointer_tother)58 void gcpointer_ctor(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_t* this)66 void gcpointer_dtor(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 operators126 // 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
r7a5d773 r3b8e52c 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); 32 33 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other); 33 34 forall(otype T) void ^?{}(gcpointer(T)* this); … … 36 37 37 38 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
r7a5d773 r3b8e52c 8 8 } 9 9 #endif 10 11 #include <fstream>12 10 13 11 #include "state.h" … … 38 36 void* gc_allocate(size_t target_size) 39 37 { 40 sout | "Allocating " | target_size | " bytes" | endl;41 42 38 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;46 39 47 40 check(size < POOL_SIZE_BYTES); -
src/examples/gc_no_raii/src/internal/state.h
r7a5d773 r3b8e52c 9 9 } 10 10 #endif 11 #include <fstream>12 11 #include <vector> 13 12 … … 38 37 static inline bool gc_needs_collect(gc_state* state) 39 38 { 40 sout | "Used Space: " | state->used_space | " bytes" | endl;41 39 return state->used_space * 2 > state->total_space; 42 40 } -
src/examples/gc_no_raii/test/gctest.c
r7a5d773 r3b8e52c 2 2 3 3 #include "gc.h" 4 #include "internal/collector.h"5 4 6 5 #warning default test … … 9 8 sout | "Bonjour au monde!\n"; 10 9 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; 10 for(int i = 0; i < 1000000; i++) { 11 gcpointer(int) anInt; 12 gcmalloc(&anInt); 21 13 } 22 23 gc_collect(gc_get_state());24 gc_conditional_collect();25 14 }
Note: See TracChangeset
for help on using the changeset viewer.