Index: src/examples/gc_no_raii/bug-repro/crash.c
===================================================================
--- src/examples/gc_no_raii/bug-repro/crash.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
+++ src/examples/gc_no_raii/bug-repro/crash.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -0,0 +1,6 @@
+
+void f()
+{
+ void* obj;
+ (void)obj;
+}
Index: src/examples/gc_no_raii/pool-alloc/allocate-malign.c
===================================================================
--- src/examples/gc_no_raii/pool-alloc/allocate-malign.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
+++ src/examples/gc_no_raii/pool-alloc/allocate-malign.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -0,0 +1,30 @@
+/*
+ * Allocation functions (posix_malign)
+ *
+ * Copyright (c) 2014, 2015 Gregor Richards
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+static void *allocPool(size_t size, int mustSucceed)
+{
+    void *ret;
+    if ((errno = posix_memalign(&ret, size, size))) {
+        if (mustSucceed) {
+            perror("posix_memalign");
+            abort();
+        }
+        return NULL;
+    }
+    return ret;
+}
Index: src/examples/gc_no_raii/pool-alloc/allocate-malloc.c
===================================================================
--- src/examples/gc_no_raii/pool-alloc/allocate-malloc.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
+++ src/examples/gc_no_raii/pool-alloc/allocate-malloc.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -0,0 +1,53 @@
+/*
+ * Allocation functions (malloc)
+ *
+ * Copyright (c) 2014, 2015 Gregor Richards
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+static void *allocPool(int mustSucceed)
+{
+    static ggc_mutex_t poolLock = GGC_MUTEX_INITIALIZER;
+    static unsigned char *space = NULL, *spaceEnd = NULL;
+    void *ret;
+
+    /* do we already have some available space? */
+    ggc_mutex_lock_raw(&poolLock);
+    if (!space || space + GGGGC_POOL_BYTES > spaceEnd) {
+        ggc_size_t i;
+
+        /* since we can't pre-align, align by getting as much as we can manage */
+        for (i = 16; i >= 2; i /= 2) {
+            space = malloc(GGGGC_POOL_BYTES * i);
+            if (space) break;
+        }
+        if (!space) {
+            if (mustSucceed) {
+                perror("malloc");
+                abort();
+            }
+            return NULL;
+        }
+        spaceEnd = space + GGGGC_POOL_BYTES * i;
+
+        /* align it */
+        space = (unsigned char *) GGGGC_POOL_OF(space + GGGGC_POOL_BYTES - 1);
+    }
+
+    ret = (struct GGGGC_Pool *) space;
+    space += GGGGC_POOL_BYTES;
+    ggc_mutex_unlock(&poolLock);
+
+    return ret;
+}
Index: src/examples/gc_no_raii/pool-alloc/allocate-mmap.c
===================================================================
--- src/examples/gc_no_raii/pool-alloc/allocate-mmap.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
+++ src/examples/gc_no_raii/pool-alloc/allocate-mmap.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -0,0 +1,44 @@
+/*
+ * Allocation functions (mmap)
+ *
+ * Copyright (c) 2014, 2015 Gregor Richards
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+static void *allocPool(int mustSucceed)
+{
+    unsigned char *space, *aspace;
+    struct GGGGC_Pool *ret;
+
+    /* allocate enough space that we can align it later */
+    space = mmap(NULL, GGGGC_POOL_BYTES*2, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+    if (space == NULL) {
+        if (mustSucceed) {
+            perror("mmap");
+            abort();
+        }
+        return NULL;
+    }
+
+    /* align it */
+    ret = GGGGC_POOL_OF(space + GGGGC_POOL_BYTES - 1);
+    aspace = (unsigned char *) ret;
+
+    /* free unused space */
+    if (aspace > space)
+        munmap(space, aspace - space);
+    munmap(aspace + GGGGC_POOL_BYTES, space + GGGGC_POOL_BYTES - aspace);
+
+    return ret;
+}
Index: src/examples/gc_no_raii/pool-alloc/allocate-win-valloc.c
===================================================================
--- src/examples/gc_no_raii/pool-alloc/allocate-win-valloc.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
+++ src/examples/gc_no_raii/pool-alloc/allocate-win-valloc.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -0,0 +1,45 @@
+/*
+ * Allocation functions (mmap)
+ *
+ * Copyright (c) 2014, 2015 Gregor Richards
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+static void *allocPool(int mustSucceed)
+{
+    unsigned char *space, *aspace;
+    struct GGGGC_Pool *ret;
+
+    /* allocate enough space that we can align it later */
+    space = (unsigned char *)
+        VirtualAlloc(NULL, GGGGC_POOL_BYTES*2, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
+    if (space == NULL) {
+        if (mustSucceed) {
+            perror("mmap");
+            abort();
+        }
+        return NULL;
+    }
+
+    /* align it */
+    ret = GGGGC_POOL_OF(space + GGGGC_POOL_BYTES - 1);
+    aspace = (unsigned char *) ret;
+
+    /* free unused space */
+    if (aspace > space)
+        VirtualFree(space, aspace - space, MEM_RELEASE);
+    VirtualFree(aspace + GGGGC_POOL_BYTES, space + GGGGC_POOL_BYTES - aspace, MEM_RELEASE);
+
+    return ret;
+}
Index: src/examples/gc_no_raii/premake4.lua
===================================================================
--- src/examples/gc_no_raii/premake4.lua	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ src/examples/gc_no_raii/premake4.lua	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -34,4 +34,8 @@
 		targetdir "."
 		buildoptions (buildOptions)
+		defines {	"bool=_Bool",
+				"\"true=((_Bool)(const signed int)1)\"",
+				"\"false=((_Bool)(const signed int)0)\"",
+				"_GNU_SOURCE"}
 		libdirs (libDirectories)
 		links (linkLibs)
@@ -41,9 +45,9 @@
 
 	configuration "debug"
-		defines { "DEBUG", "bool=_Bool" }
+		defines { "DEBUG" }
 		flags { "Symbols" }
 
 	configuration "release"
-		defines { "NDEBUG", "bool=_Bool" }
+		defines { "NDEBUG" }
 		flags { "Optimize" }
 
@@ -51,5 +55,5 @@
 		buildoptions ({"-E"})
 		linkoptions ({"-E"})
-	      defines { "DEBUG", "bool=_Bool" }
+	      defines { "DEBUG" }
 	      flags { "Symbols" }
 
@@ -57,5 +61,5 @@
 		buildoptions ({"-E"})
 		linkoptions ({"-E"})
-	      defines { "DEBUG", "bool=_Bool" }
+	      defines { "DEBUG" }
 	      flags { "Symbols" }
 
@@ -63,5 +67,5 @@
 		linkoptions ({"-E"})
 		files { "build/cproc-debug/*.o" }
-	      defines { "DEBUG", "bool=_Bool" }
+	      defines { "DEBUG" }
 	      flags { "Symbols" }
 
@@ -69,4 +73,4 @@
 		linkoptions ({"-E"})
 		files { "build/cproc-debug/*.o" }
-	      defines { "DEBUG", "bool=_Bool" }
+	      defines { "DEBUG" }
 	      flags { "Symbols" }
Index: c/examples/gc_no_raii/src/allocate-malign.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-malign.c	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ 	(revision )
@@ -1,30 +1,0 @@
-/*
- * Allocation functions (posix_malign)
- *
- * Copyright (c) 2014, 2015 Gregor Richards
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-static void *allocPool(size_t size, int mustSucceed)
-{
-    void *ret;
-    if ((errno = posix_memalign(&ret, size, size))) {
-        if (mustSucceed) {
-            perror("posix_memalign");
-            abort();
-        }
-        return NULL;
-    }
-    return ret;
-}
Index: c/examples/gc_no_raii/src/allocate-malloc.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-malloc.c	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ 	(revision )
@@ -1,53 +1,0 @@
-/*
- * Allocation functions (malloc)
- *
- * Copyright (c) 2014, 2015 Gregor Richards
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-static void *allocPool(int mustSucceed)
-{
-    static ggc_mutex_t poolLock = GGC_MUTEX_INITIALIZER;
-    static unsigned char *space = NULL, *spaceEnd = NULL;
-    void *ret;
-
-    /* do we already have some available space? */
-    ggc_mutex_lock_raw(&poolLock);
-    if (!space || space + GGGGC_POOL_BYTES > spaceEnd) {
-        ggc_size_t i;
-
-        /* since we can't pre-align, align by getting as much as we can manage */
-        for (i = 16; i >= 2; i /= 2) {
-            space = malloc(GGGGC_POOL_BYTES * i);
-            if (space) break;
-        }
-        if (!space) {
-            if (mustSucceed) {
-                perror("malloc");
-                abort();
-            }
-            return NULL;
-        }
-        spaceEnd = space + GGGGC_POOL_BYTES * i;
-
-        /* align it */
-        space = (unsigned char *) GGGGC_POOL_OF(space + GGGGC_POOL_BYTES - 1);
-    }
-
-    ret = (struct GGGGC_Pool *) space;
-    space += GGGGC_POOL_BYTES;
-    ggc_mutex_unlock(&poolLock);
-
-    return ret;
-}
Index: c/examples/gc_no_raii/src/allocate-mmap.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-mmap.c	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ 	(revision )
@@ -1,44 +1,0 @@
-/*
- * Allocation functions (mmap)
- *
- * Copyright (c) 2014, 2015 Gregor Richards
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-static void *allocPool(int mustSucceed)
-{
-    unsigned char *space, *aspace;
-    struct GGGGC_Pool *ret;
-
-    /* allocate enough space that we can align it later */
-    space = mmap(NULL, GGGGC_POOL_BYTES*2, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
-    if (space == NULL) {
-        if (mustSucceed) {
-            perror("mmap");
-            abort();
-        }
-        return NULL;
-    }
-
-    /* align it */
-    ret = GGGGC_POOL_OF(space + GGGGC_POOL_BYTES - 1);
-    aspace = (unsigned char *) ret;
-
-    /* free unused space */
-    if (aspace > space)
-        munmap(space, aspace - space);
-    munmap(aspace + GGGGC_POOL_BYTES, space + GGGGC_POOL_BYTES - aspace);
-
-    return ret;
-}
Index: src/examples/gc_no_raii/src/allocate-pool.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-pool.c	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ src/examples/gc_no_raii/src/allocate-pool.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -1,4 +1,5 @@
 #define _BSD_SOURCE /* for MAP_ANON */
 #define _DARWIN_C_SOURCE /* for MAP_ANON on OS X */
+
 
 /* for standards info */
@@ -25,6 +26,6 @@
 #endif
 
-#ifdef __cplusplus
-extern "C" {
+#ifdef CFA
+extern "C"{
 #endif
 
@@ -32,22 +33,22 @@
 #if defined(GGGGC_USE_MALLOC)
 #define GGGGC_ALLOCATOR_MALLOC 1
-#include "allocate-malloc.cpp"
+#include "../pool-alloc/allocate-malloc.c"
 
 #elif _POSIX_ADVISORY_INFO >= 200112L
 #define GGGGC_ALLOCATOR_POSIX_MEMALIGN 1
-#include "allocate-malign.cpp"
+#include "../pool-alloc/allocate-malign.c"
 
 #elif defined(MAP_ANON)
 #define GGGGC_ALLOCATOR_MMAP 1
-#include "allocate-mmap.cpp"
+#include "../pool-alloc/allocate-mmap.c"
 
 #elif defined(_WIN32)
 #define GGGGC_ALLOCATOR_VIRTUALALLOC 1
-#include "allocate-win-valloc.cpp"
+#include "../pool-alloc/allocate-win-valloc.c"
 
 #else
 #warning GGGGC: No allocator available other than malloc!
 #define GGGGC_ALLOCATOR_MALLOC 1
-#include "allocate-malloc.cpp"
+#include "../pool-alloc/allocate-malloc.c"
 
 #endif
@@ -58,5 +59,5 @@
 }
 
-#ifdef __cplusplus
+#ifdef CFA
 }
 #endif
Index: c/examples/gc_no_raii/src/allocate-win-valloc.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-win-valloc.c	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/*
- * Allocation functions (mmap)
- *
- * Copyright (c) 2014, 2015 Gregor Richards
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-static void *allocPool(int mustSucceed)
-{
-    unsigned char *space, *aspace;
-    struct GGGGC_Pool *ret;
-
-    /* allocate enough space that we can align it later */
-    space = (unsigned char *)
-        VirtualAlloc(NULL, GGGGC_POOL_BYTES*2, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
-    if (space == NULL) {
-        if (mustSucceed) {
-            perror("mmap");
-            abort();
-        }
-        return NULL;
-    }
-
-    /* align it */
-    ret = GGGGC_POOL_OF(space + GGGGC_POOL_BYTES - 1);
-    aspace = (unsigned char *) ret;
-
-    /* free unused space */
-    if (aspace > space)
-        VirtualFree(space, aspace - space, MEM_RELEASE);
-    VirtualFree(aspace + GGGGC_POOL_BYTES, space + GGGGC_POOL_BYTES - aspace, MEM_RELEASE);
-
-    return ret;
-}
Index: src/examples/gc_no_raii/src/internal/collector.c
===================================================================
--- src/examples/gc_no_raii/src/internal/collector.c	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ src/examples/gc_no_raii/src/internal/collector.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -1,4 +1,5 @@
 #include "collector.h"
 
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -7,7 +8,5 @@
 #include "fstream.h"
 
-#include "gc_tools.h"
-#include "state.h"
-// #include "memory_pool.h"
+#include "memory_pool.h"
 
 void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size);
@@ -69,5 +68,5 @@
 	gc_object_header* obj = gc_object_header_placement_ctor(header, actual_size);
 
-	(void)obj; //remove unsused warning since this is for debug
+	// (void)obj; //remove unsused warning since this is for debug
 	check(obj == get_object_ptr(data));
 
@@ -77,67 +76,67 @@
 }
 
-// 	void process_reference(void** ref, std::vector<void**>& worklist)
-// 	{
-// 		check(!gc::gc_get_state().is_in_heap(ref));
-//
-// 		if(gc_object_header* ptr = get_object_ptr(*ref))
-// 		{
-// 			if(!ptr->is_forwarded)
-// 			{
-// 				copy_object(ptr);
-//
-// 				scan_object(ptr->forward, worklist);
-//
-// 				assign_reference(ref, ptr->forward);
-// 			}
-// 			else
-// 			{
-// 				//duplication to help debug
-// 				assign_reference(ref, ptr->forward);
-// 			}
-// 		}
-// 	}
-//
-// 	void assign_reference(void** ref, gc_object_header* ptr)
-// 	{
-// 		void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header));
-//
-// 		write_aligned_ptr(ref, address);
-// 	}
-//
-// 	gc_object_header* copy_object(gc_object_header* ptr)
-// 	{
-// 		check(!ptr->forward);
-// 		check(!ptr->is_forwarded);
-// 		check(pool_of(ptr)->is_from_space());
-//
-// 		memory_pool* pool = pool_of(ptr)->mirror();
-//
-// 		void* new_block = pool->allocate(ptr->size, false);
-//
-// 		std::memcpy(new_block, ptr, ptr->size);
-//
-// 		gc_object_header* fwd_ptr = new (new_block) gc_object_header(ptr);
-//
-// 		ptr->forward = fwd_ptr;
-// 		ptr->is_forwarded = true;
-//
-// 		return fwd_ptr;
-// 	}
-//
-// 	void scan_object(gc_object_header* object, std::vector<void**>& worklist)
-// 	{
-// 		gcpointer_base* type = object->type_chain;
-// 		while(type)
-// 		{
-// 			check(((intptr_t)type) > ((intptr_t)object));
-// 			check(((intptr_t)type) < ((intptr_t)((intptr_t)object) + object->size));
-//
-// 			check(gc::gc_get_state().is_in_to_space(&type->m_ptr));
-//
-// 			worklist.push_back(&type->m_ptr);
-//
-// 			type = type->m_next;
-// 		}
-// 	}
-// };
+void gc_process_reference(void** ref, worklist_t* worklist)
+{
+	check(!gc_is_in_heap(gc_get_state(), ref));
+
+	gc_object_header* ptr = gc_get_object_ptr(*ref);
+	if(ptr)
+	{
+		if(!ptr->is_forwarded)
+		{
+			gc_copy_object(ptr);
+
+			gc_scan_object(ptr->forward, worklist);
+
+			gc_assign_reference(ref, ptr->forward);
+		}
+		else
+		{
+			//duplication to help debug
+			gc_assign_reference(ref, ptr->forward);
+		}
+	}
+}
+
+void gc_assign_reference(void** ref, gc_object_header* ptr)
+{
+	void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header));
+
+	gc_write_aligned_ptr(ref, address);
+}
+
+gc_object_header* gc_copy_object(gc_object_header* ptr)
+{
+	check(!ptr->forward);
+	check(!ptr->is_forwarded);
+	check(gc_is_from_space(gc_pool_of(ptr)));
+
+	gc_memory_pool* pool = gc_pool_of(ptr)->mirror;
+
+	void* new_block = gc_pool_allocate(pool, ptr->size, true);
+
+	memcpy(new_block, ptr, ptr->size);
+
+	gc_object_header* fwd_ptr = gc_object_header_placement_copy_ctor(new_block, ptr);
+
+	ptr->forward = fwd_ptr;
+	ptr->is_forwarded = true;
+
+	return fwd_ptr;
+}
+
+void gc_scan_object(gc_object_header* object, worklist_t* worklist)
+{
+	gcpointer_t* field = object->type_chain;
+	while(field)
+	{
+		check(((intptr_t)field) > ((intptr_t)object));
+		check(((intptr_t)field) < ((intptr_t)((intptr_t)object) + object->size));
+
+		check(gc_is_in_to_space(gc_get_state(), &type->ptr));
+
+		push_back(worklist, &field->ptr);
+
+		field = field->next;
+	}
+}
Index: src/examples/gc_no_raii/src/internal/collector.h
===================================================================
--- src/examples/gc_no_raii/src/internal/collector.h	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ src/examples/gc_no_raii/src/internal/collector.h	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -12,6 +12,5 @@
 #include "internal/object_header.h"
 #include "internal/state.h"
-
-typedef int worklist_t;
+#include "tools/worklist.h"
 
 inline bool gc_is_managed(void* address)
@@ -26,5 +25,5 @@
 }
 
-inline gc_memory_pool* pool_of(void* address)
+inline gc_memory_pool* gc_pool_of(void* address)
 {
 	return (struct gc_memory_pool*)(((intptr_t)address) & POOL_PTR_MASK);
Index: src/examples/gc_no_raii/src/internal/memory_pool.h
===================================================================
--- src/examples/gc_no_raii/src/internal/memory_pool.h	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
+++ src/examples/gc_no_raii/src/internal/memory_pool.h	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -0,0 +1,74 @@
+#pragma once
+
+#include <stdint.h>
+
+#include "tools.h"
+
+// #include "card_table.h"
+#include "collector.h"
+#include "globals.h"
+
+typedef int cardtable_ptr_t;
+
+struct gc_memory_pool
+{
+	struct memory_pool* mirror;
+	struct memory_pool* next;
+
+	uint8_t type_code;
+
+	cardtable_ptr_t cards;
+
+	uint8_t* end_p;
+	uint8_t* free_p;
+	uint8_t start_p[1];
+};
+
+struct gc_pool_object_iterator
+{
+
+	struct gc_object_header* object;
+	#if _DEBUG
+		intptr_t lower_limit;
+		intptr_t upper_limit;
+	#endif
+};
+
+
+void gc_pool_object_iterator_ctor(
+		struct gc_object_header* start_object
+		#if _DEBUG
+			, intptr_t pool_start
+			, intptr_t pool_end
+		#endif
+	);
+
+bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
+
+gc_pool_object_iterator* ++?(gc_pool_object_iterator* it);
+
+const struct gc_object_header* *?(const gc_pool_object_iterator it);
+struct gc_object_header* *?(gc_pool_object_iterator it);
+
+inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
+{
+	return gc_from_space_code(gc_get_state()) == pool->type_code;
+}
+
+void gc_reset_pool(gc_memory_pool* pool);
+
+inline size_t gc_pool_size_total(const gc_memory_pool* pool)
+{
+	return pool->end_p - pool->start_p;
+}
+
+inline size_t gc_pool_size_left(const gc_memory_pool* pool)
+{
+	return pool->end_p - pool->free_p;
+}
+
+void* gc_pool_allocate(gc_memory_pool* pool, size_t size, bool zero);
+
+gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* pool, void* member);
+
+gc_pool_object_iterator gc_pool_end(gc_memory_pool* pool);
Index: src/examples/gc_no_raii/src/internal/object_header.h
===================================================================
--- src/examples/gc_no_raii/src/internal/object_header.h	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ src/examples/gc_no_raii/src/internal/object_header.h	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -31,2 +31,3 @@
 
 gc_object_header* gc_object_header_placement_ctor(void* address, size_t size);
+gc_object_header* gc_object_header_placement_copy_ctor(void* address, gc_object_header* other);
Index: src/examples/gc_no_raii/src/internal/state.c
===================================================================
--- src/examples/gc_no_raii/src/internal/state.c	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ src/examples/gc_no_raii/src/internal/state.c	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -1,3 +1,5 @@
 #include "state.h"
+
+#include <stdlib.h>
 
 //general purpouse includes
@@ -9,5 +11,5 @@
 //gc internal includes
 // #include "globals.h"
-// #include "memory_pool.h"
+#include "memory_pool.h"
 // #include "memory_pool_iterator.h"
 // #include "object_header.h"
@@ -22,20 +24,22 @@
 // 	bool no_from_space_ref(gc_state* state);
 // #endif
-//
-// void gc_state_ctor(gc_state* state)
-// {
-// 	state->from_code(0)
-// 	state->to_space(nullptr)
-// 	state->from_space(nullptr)
-// 	state->total_space(0)
-// 	state->used_space(0)
-// 	state->pools_table()
-//
-// 	gc_allocate_pool(gc_state* state);
-// }
-//
+
+void gc_state_ctor(gc_state* state)
+{
+	state->from_code = 0;
+	state->to_space = NULL;
+	state->from_space = NULL;
+	state->total_space = 0;
+	state->used_space = 0;
+	// state->pools_table();
+
+	gc_allocate_pool(state);
+
+	state->is_initialized = true;
+}
+
 // bool state::is_in_heap(void* address) const
 // {
-// 	memory_pool* target_pool = pool_of(address);
+// 	memory_pool* target_pool = gc_pool_of(address);
 //
 // 	auto first = pools_table.cbegin();
@@ -44,5 +48,5 @@
 // 	return result != last && (*result)->is_from_space();
 // }
-//
+
 // bool state::is_in_to_space(void* address) const
 // {
@@ -55,31 +59,31 @@
 // }
 //
-// object_header* state::get_object_for_ref(void* member)
-// {
-// 	intptr_t target = intptr_t(member);
-// 	if(!is_in_heap(member)) return nullptr;
-//
-// 	memory_pool* pool = pool_of(member);
-// 	auto it = pool->iterator_for(member);
-// 	auto end = pool->end();
-//
-// 	while(it != end)
-// 	{
-// 		object_header* object = *it;
-// 		{
-// 			intptr_t start = intptr_t(object);
-// 			intptr_t end = intptr_t(start + object->size);
-// 			if(start < target && end > target)
-// 			{
-// 				return object;
-// 			}
-// 		}
-// 		++it;
-// 	}
-//
-// 	checkf(false, "is_in_heap() and iterator_for() return inconsistent data");
-// 	abort();
-// 	return nullptr;
-// }
+gc_object_header* gc_get_object_for_ref(gc_state* state, void* member)
+{
+	intptr_t target = ((intptr_t)member);
+	if(!gc_is_in_heap(state, member)) return NULL;
+
+	gc_memory_pool* pool = gc_pool_of(member);
+	gc_pool_object_iterator it = gc_pool_iterator_for(pool, member);
+	gc_pool_object_iterator end = gc_pool_end(pool);
+
+	while(it != end)
+	{
+		gc_object_header* object = *it;
+		{
+			intptr_t start = ((intptr_t)object);
+			intptr_t end = ((intptr_t)start + object->size);
+			if(start < target && end > target)
+			{
+				return object;
+			}
+		}
+		++it;
+	}
+
+	checkf(false, "is_in_heap() and iterator_for() return inconsistent data");
+	abort();
+	return NULL;
+}
 //
 // void* state::try_allocate(size_t size)
Index: src/examples/gc_no_raii/src/internal/state.h
===================================================================
--- src/examples/gc_no_raii/src/internal/state.h	(revision 08a40fd0ac2822ce5d15d21cb33a99415eeaaaed)
+++ src/examples/gc_no_raii/src/internal/state.h	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -16,6 +16,6 @@
 	size_t used_space;
 
-	const struct memory_pool* 	pools_table;
-	size_t 				pools_table_count;
+	// const struct memory_pool* 	pools_table;
+	// size_t 				pools_table_count;
 };
 
Index: src/examples/gc_no_raii/src/tools/worklist.h
===================================================================
--- src/examples/gc_no_raii/src/tools/worklist.h	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
+++ src/examples/gc_no_raii/src/tools/worklist.h	(revision d67a9a18d6d1684db38cd3027bb168bb8bd75201)
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef intptr_t* worklist_element_t;
+
+struct worklist_t
+{
+	size_t count;
+	worklist_element_t* data;
+};
+
+void push_back(worklist_t* worklist, worklist_element_t element);
