52#include "M2/gc-include.h"
54#include <gc/gc_allocator.h>
76using gc_vector =
typename std::vector<T, gc_allocator<T>>;
78#define VECTOR(T) gc_vector<T>
82#define newarray(T, len) reinterpret_cast<T *>(getmem((len) * sizeof(T)))
83#define newarray_clear(T, len) \
84 reinterpret_cast<T *>(getmem_clear((len) * sizeof(T)))
86#define newitem(T) reinterpret_cast<T *>(getmem(sizeof(T)))
87#define newitem_clear(T) reinterpret_cast<T *>(getmem_clear(sizeof(T)))
91#define newarray_atomic(T, len) \
92 reinterpret_cast<T *>(getmem_atomic((len) * sizeof(T)))
93#define newarray_atomic_clear(T, len) \
94 reinterpret_cast<T *>(getmem_atomic_clear((len) * sizeof(T)))
96#define newitem_atomic(T) reinterpret_cast<T *>(getmem_atomic(sizeof(T)))
101#define GETMEM(T, size) reinterpret_cast<T>(getmem(size))
102#define GETMEM_ATOMIC(T, size) reinterpret_cast<T>(getmem_atomic(size))
113#define ARRAY_ON_STACK(type, nelems) static_cast<type*>(alloca(nelems * sizeof(type)))
117 static inline void *
operator new(
size_t size)
125 static inline void *
operator new[](
size_t size)
134 static inline void operator delete(
void *obj)
139 static inline void operator delete[](
void *obj)
145 static inline void *
operator new(
size_t size,
void *existing_memory)
148 return existing_memory;
150 static inline void *
operator new[](
size_t size,
void *existing_memory)
153 return existing_memory;
156 static inline void operator delete(
void *obj,
void *existing_memory)
158 (void) existing_memory;
161 static inline void operator delete[](
void *obj,
void *existing_memory)
163 (void) existing_memory;
168#if !defined(__GNUC__) || defined(__INTEL_COMPILER)
190 if (0 == GC_base(
this))
return;
192 GC_REGISTER_FINALIZER_IGNORE_SELF(M2_debug_to_outer((
void*)
this), 0, 0, 0, 0);
194 GC_REGISTER_FINALIZER_IGNORE_SELF(
this, 0, 0, 0, 0);
199static inline void cleanup(
void* obj,
void* displ)
203 obj = M2_debug_to_inner(obj);
210 if (0 == GC_base(
this))
return;
212 GC_REGISTER_FINALIZER_IGNORE_SELF(M2_debug_to_outer(
this), (GC_finalization_proc)
cleanup, 0, 0, 0);
214 GC_REGISTER_FINALIZER_IGNORE_SELF(
this, (GC_finalization_proc)
cleanup, 0, 0, 0);
virtual ~our_gc_cleanup()
void outofmem2(size_t newsize)
Engine-wide GC allocator surface (getmem / getmem_atomic) and debug-allocation trap.
typename std::vector< T, gc_allocator< T > > gc_vector
a version of the STL vector, which allocates its backing memory with gc.
static void cleanup(void *obj, void *displ)