Changes in / [7a5d773:3b8e52c]


Ignore:
Location:
src/examples/gc_no_raii
Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/premake4.lua

    r7a5d773 r3b8e52c  
    66        "src/",
    77        "../",
    8         "containers/"
    98}
    109
     
    4948                linkoptions (linkOptionList)
    5049                includedirs (includeDirList)
    51                 files { "src/**.c", "containers/**.c" }
     50                files { "src/**.c" }
    5251
    5352        configuration "debug"
  • src/examples/gc_no_raii/src/gc.h

    r7a5d773 r3b8e52c  
    44#include "internal/collector.h"
    55
    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 // }
     6forall(otype T)
     7static inline gcpointer(T) gcmalloc()
     8{
     9    gcpointer(T) ptr = { gc_allocate(sizeof(T)) };
     10    ptr{};
     11    gc_conditional_collect();
     12    return ptr;
     13}
    1414
    1515forall(otype T)
    1616static inline void gcmalloc(gcpointer(T)* ptr)
    1717{
    18         ptr { gc_allocate(sizeof(T)) };
    19         get(ptr) {};
     18        ptr{ gc_allocate(sizeof(T)) };
     19      (*ptr){};
    2020      gc_conditional_collect();
    2121}
  • src/examples/gc_no_raii/src/gcpointers.c

    r7a5d773 r3b8e52c  
    4242}
    4343
    44 void ?{}(gcpointer_t* this)
     44void gcpointer_ctor(gcpointer_t* this)
    4545{
    4646        this->ptr = (intptr_t)NULL;
     
    4848}
    4949
    50 void ?{}(gcpointer_t* this, void* address)
     50void gcpointer_ctor(gcpointer_t* this, void* address)
    5151{
    5252        this->ptr = (intptr_t)address;
     
    5656}
    5757
    58 void ?{}(gcpointer_t* this, gcpointer_t other)
     58void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other)
    5959{
    60         this->ptr = other.ptr;
     60        this->ptr = other->ptr;
    6161        this->next = NULL;
    6262
     
    6464}
    6565
    66 void ^?{}(gcpointer_t* this)
     66void gcpointer_dtor(gcpointer_t* this)
    6767{
    6868        unregister_ptr(this);
     
    9898        return this->ptr == (intptr_t)NULL;
    9999}
    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

    r7a5d773 r3b8e52c  
    3030forall(otype T) void ?{}(gcpointer(T)* this);
    3131forall(otype T) void ?{}(gcpointer(T)* this, void* address);
     32forall(otype T) void ctor(gcpointer(T)* this, void* address);
    3233forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other);
    3334forall(otype T) void ^?{}(gcpointer(T)* this);
     
    3637
    3738forall(otype T) T *?(gcpointer(T) this);
    38 forall(otype T) T* get(gcpointer(T)* this);
    3939
    4040//Logical operators
  • src/examples/gc_no_raii/src/internal/collector.c

    r7a5d773 r3b8e52c  
    88}
    99#endif
    10 
    11 #include <fstream>
    1210
    1311#include "state.h"
     
    3836void* gc_allocate(size_t target_size)
    3937{
    40         sout | "Allocating " | target_size | " bytes" | endl;
    41 
    4238        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;
    4639
    4740        check(size < POOL_SIZE_BYTES);
  • src/examples/gc_no_raii/src/internal/state.h

    r7a5d773 r3b8e52c  
    99}
    1010#endif
    11 #include <fstream>
    1211#include <vector>
    1312
     
    3837static inline bool gc_needs_collect(gc_state* state)
    3938{
    40         sout | "Used Space: " | state->used_space | " bytes" | endl;
    4139        return state->used_space * 2 > state->total_space;
    4240}
  • src/examples/gc_no_raii/test/gctest.c

    r7a5d773 r3b8e52c  
    22
    33#include "gc.h"
    4 #include "internal/collector.h"
    54
    65#warning default test
     
    98        sout | "Bonjour au monde!\n";
    109
    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);
    2113        }
    22 
    23         gc_collect(gc_get_state());
    24         gc_conditional_collect();
    2514}
Note: See TracChangeset for help on using the changeset viewer.