Index: src/examples/gc_no_raii/premake4.lua
===================================================================
--- src/examples/gc_no_raii/premake4.lua	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/premake4.lua	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -38,5 +38,5 @@
 		linkoptions (linkOptionList)
 		includedirs (includeDirList)
-		files { "../fstream.c", "../iostream.c", "../iterator.c", "src/*.c" }
+		files { "../fstream.c", "../iostream.c", "../iterator.c", "src/**.c" }
 
 	configuration "debug"
Index: src/examples/gc_no_raii/src/allocate-malign.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-malign.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
+++ src/examples/gc_no_raii/src/allocate-malign.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -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/src/allocate-malloc.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-malloc.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
+++ src/examples/gc_no_raii/src/allocate-malloc.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -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/src/allocate-mmap.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-mmap.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
+++ src/examples/gc_no_raii/src/allocate-mmap.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -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/src/allocate-pool.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-pool.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
+++ src/examples/gc_no_raii/src/allocate-pool.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -0,0 +1,62 @@
+#define _BSD_SOURCE /* for MAP_ANON */
+#define _DARWIN_C_SOURCE /* for MAP_ANON on OS X */
+
+/* for standards info */
+#if defined(unix) || defined(__unix) || defined(__unix__) || \
+    (defined(__APPLE__) && defined(__MACH__))
+#include <unistd.h>
+#endif
+
+#if defined(_WIN32)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#if _POSIX_VERSION
+#include <sys/mman.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* figure out which allocator to use */
+#if defined(GGGGC_USE_MALLOC)
+#define GGGGC_ALLOCATOR_MALLOC 1
+#include "allocate-malloc.cpp"
+
+#elif _POSIX_ADVISORY_INFO >= 200112L
+#define GGGGC_ALLOCATOR_POSIX_MEMALIGN 1
+#include "allocate-malign.cpp"
+
+#elif defined(MAP_ANON)
+#define GGGGC_ALLOCATOR_MMAP 1
+#include "allocate-mmap.cpp"
+
+#elif defined(_WIN32)
+#define GGGGC_ALLOCATOR_VIRTUALALLOC 1
+#include "allocate-win-valloc.cpp"
+
+#else
+#warning GGGGC: No allocator available other than malloc!
+#define GGGGC_ALLOCATOR_MALLOC 1
+#include "allocate-malloc.cpp"
+
+#endif
+
+void* pal_allocPool(size_t size, int mustSucceed)
+{
+      return allocPool(size, mustSucceed);
+}
+
+#ifdef __cplusplus
+}
+#endif
Index: src/examples/gc_no_raii/src/allocate-pool.h
===================================================================
--- src/examples/gc_no_raii/src/allocate-pool.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
+++ src/examples/gc_no_raii/src/allocate-pool.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -0,0 +1,14 @@
+#ifndef _GGGGC_ALlOCATE_POOL_H_
+#define _GGGGC_ALlOCATE_POOL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void* pal_allocPool(size_t size, int mustSucceed);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: src/examples/gc_no_raii/src/allocate-win-valloc.c
===================================================================
--- src/examples/gc_no_raii/src/allocate-win-valloc.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
+++ src/examples/gc_no_raii/src/allocate-win-valloc.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -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/src/gc.h
===================================================================
--- src/examples/gc_no_raii/src/gc.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/gc.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -3,7 +3,7 @@
 #include "gcpointers.h"
 
-forall( dtype T )
-gcpointer_t gcmalloc()
-{
-
-}
+// forall( dtype T )
+// gcpointer_t gcmalloc()
+// {
+//
+// }
Index: src/examples/gc_no_raii/src/gcpointers.c
===================================================================
--- src/examples/gc_no_raii/src/gcpointers.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/gcpointers.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -4,5 +4,5 @@
 #include "internal/collector.h"
 #include "internal/object_header.h"
-#include "internal/state.h"
+// #include "internal/state.h"
 
 void register_ptr(gcpointer_t* this)
@@ -14,9 +14,9 @@
 	if(managed)
 	{
-		gc_object_header* obj = gc_get_object_for_ref(this);
+		gc_object_header* obj = gc_get_object_for_ref(gc_get_state(), (void*)this);
 		check(obj);
 		check(gc_obj_is_valide(obj));
 		check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
-		m_next = obj->type_chain;
+		this->next = obj->type_chain;
 		obj->type_chain = this;
 		check(obj->is_valide());
@@ -24,9 +24,9 @@
 	else
 	{
-		gc_object_header* obj = gc_get_object_ptr(this->ptr);
+		gc_object_header* obj = gc_get_object_ptr((void*)this->ptr);
 		check(obj);
 		check(gc_obj_is_valide(obj));
 		check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL);
-		m_next = obj->root_chain;
+		this->next = obj->root_chain;
 		obj->root_chain = this;
 		check(gc_obj_is_valide(obj));
@@ -46,5 +46,5 @@
 void gcpointer_ctor(gcpointer_t* this)
 {
-	this->ptr = NULL;
+	this->ptr = (intptr_t)NULL;
 	this->next = NULL;
 }
@@ -52,5 +52,5 @@
 void gcpointer_ctor(gcpointer_t* this, void* address)
 {
-	this->ptr = address;
+	this->ptr = (intptr_t)address;
 	this->next = NULL;
 
@@ -73,5 +73,5 @@
 gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs)
 {
-	if(this != rhs && this->ptr != rhs->ptr)
+	if(this != rhs)
 	{
 		unregister_ptr(this);
@@ -98,4 +98,4 @@
 int gcpointer_null(gcpointer_t* this)
 {
-	return this->ptr == NULL;
+	return this->ptr == (intptr_t)NULL;
 }
Index: src/examples/gc_no_raii/src/gcpointers.h
===================================================================
--- src/examples/gc_no_raii/src/gcpointers.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/gcpointers.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -1,7 +1,9 @@
 #pragma once
+
+#include <stdint.h>
 
 struct gcpointer_t
 {
-	void* ptr;
+	intptr_t ptr;
 	struct gcpointer_t* next;
 };
Index: src/examples/gc_no_raii/src/internal/collector.c
===================================================================
--- src/examples/gc_no_raii/src/internal/collector.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
+++ src/examples/gc_no_raii/src/internal/collector.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -0,0 +1,142 @@
+#include "collector.h"
+
+#include <stdint.h>
+#include <string.h>
+
+#include "fstream.h"
+
+#include "gc_tools.h"
+#include "state.h"
+#include "memory_pool.h"
+
+void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size);
+void gc_assign_reference(void** ref, gc_object_header* ptr);
+
+gcpointer_t** gc_find_previous_ref(gcpointer_t* target)
+{
+	if(!(target)) return NULL;
+
+	bool managed = gc_is_managed(target);
+	gc_object_header* obj = gc_get_object_ptr(target->ptr);
+
+	check(gc_is_valide(obj));
+
+	gcpointer_t** prev_next_ptr = managed ? &obj->type_chain : &obj->root_chain;
+	while((*prev_next_ptr) && (*prev_next_ptr) != target)
+	{
+		prev_next_ptr = &(*prev_next_ptr)->next;
+	}
+
+	return prev_next_ptr;
+}
+
+void* gc_allocate(size_t target_size)
+{
+	size_t size = gc_compute_size(target_size + sizeof(gc_object_header));
+
+	check(size < POOL_SIZE_BYTES);
+
+	void* block = nullptr;
+	gc_state* gc = gc_get_state();
+
+	if((block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
+
+	gc_collect(gc);
+
+	if((block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
+
+	gc_allocate_pool(gc);
+
+	if((block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
+
+	ofstream_stderr() | "ERROR: allocation in new pool failed" | endl;
+	abort();
+
+	return nullptr;
+}
+
+void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size)
+{
+	void* data = (void*)(intptr_t(block) + sizeof(object_header));
+	void* header = block;
+
+	check(intptr_t(data) > intptr_t(block));
+	check(intptr_t(data) >= intptr_t(header));
+	check(is_aligned(data));
+	check(intptr_t(data) + target_size <= intptr_t(block) + actual_size);
+
+	object_header* obj = gc_object_header_placement_ctor(header, actual_size);
+
+	(void)obj; //remove unsused warning since this is for debug
+	check(obj == get_object_ptr(data));
+
+	gc_register_allocation(get_state(), actual_size);
+
+	return data;
+}
+
+// 	void process_reference(void** ref, std::vector<void**>& worklist)
+// 	{
+// 		check(!gc::get_state().is_in_heap(ref));
+//
+// 		if(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, object_header* ptr)
+// 	{
+// 		void* address = (void*)(intptr_t(ptr) + sizeof(object_header));
+//
+// 		write_aligned_ptr(ref, address);
+// 	}
+//
+// 	object_header* copy_object(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);
+//
+// 		object_header* fwd_ptr = new (new_block) object_header(ptr);
+//
+// 		ptr->forward = fwd_ptr;
+// 		ptr->is_forwarded = true;
+//
+// 		return fwd_ptr;
+// 	}
+//
+// 	void scan_object(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::get_state().is_in_to_space(&type->m_ptr));
+//
+// 			worklist.push_back(&type->m_ptr);
+//
+// 			type = type->m_next;
+// 		}
+// 	}
+// };
Index: src/examples/gc_no_raii/src/internal/collector.h
===================================================================
--- src/examples/gc_no_raii/src/internal/collector.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/collector.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -20,11 +20,11 @@
 }
 
-inline struct gc_object_header* gc_get_object_ptr(void* ptr)
+inline gc_object_header* gc_get_object_ptr(void* ptr)
 {
 	void* clean = gc_get_aligned_ptr(ptr);
-	return ((struct gc_object_header*)clean) - 1;
+	return ((gc_object_header*)clean) - 1;
 }
 
-inline struct gc_memory_pool* pool_of(void* address)
+inline gc_memory_pool* pool_of(void* address)
 {
 	return (struct gc_memory_pool*)(((intptr_t)address) & POOL_PTR_MASK);
Index: src/examples/gc_no_raii/src/internal/globals.h
===================================================================
--- src/examples/gc_no_raii/src/internal/globals.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/globals.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -1,16 +1,29 @@
 #pragma once
 
-#include <stddef.h>
-#include <stdint.h>
+// #include <stddef.h>
+// #include <stdint.h>
+//
+// static const size_t POOL_SIZE_EXP = 24;
+// static const size_t POOL_SIZE_BYTES = 0x1 << POOL_SIZE_EXP;
+// static const size_t POOL_PTR_MASK = ~(POOL_SIZE_BYTES - 1);
+//
+// static const size_t CARDS_SIZE_EXP = 12;
+// static const size_t CARDS_SIZE_BYTES = 0x1 << CARDS_SIZE_EXP;
+// static const size_t CARDS_OFFSET_MASK = (~(CARDS_SIZE_BYTES - 1)) & (POOL_SIZE_BYTES - 1);
+// static const size_t CARDS_COUNT = POOL_SIZE_BYTES / CARDS_SIZE_BYTES;
+//
+// static const size_t OBJECT_ALLIGNMENT = sizeof(size_t);
+// static const size_t OBJECT_PTR_MASK = ~(OBJECT_ALLIGNMENT - 1);
 
-static const size_t POOL_SIZE_EXP = 24;
-static const size_t POOL_SIZE_BYTES = 0x1 << POOL_SIZE_EXP;
-static const size_t POOL_PTR_MASK = ~(POOL_SIZE_BYTES - 1);
 
-static const size_t CARDS_SIZE_EXP = 12;
-static const size_t CARDS_SIZE_BYTES = 0x1 << CARDS_SIZE_EXP;
-static const size_t CARDS_OFFSET_MASK = (~(CARDS_SIZE_BYTES - 1)) & (POOL_SIZE_BYTES - 1);
-static const size_t CARDS_COUNT = POOL_SIZE_BYTES / CARDS_SIZE_BYTES;
+#define POOL_SIZE_EXP 24
+#define POOL_SIZE_BYTES 0x1 << POOL_SIZE_EXP
+#define POOL_PTR_MASK ~(POOL_SIZE_BYTES - 1)
 
-static const size_t OBJECT_ALLIGNMENT = sizeof(size_t);
-static const size_t OBJECT_PTR_MASK = ~(OBJECT_ALLIGNMENT - 1);
+#define CARDS_SIZE_EXP 12
+#define CARDS_SIZE_BYTES 0x1 << CARDS_SIZE_EXP
+#define CARDS_OFFSET_MASK (~(CARDS_SIZE_BYTES - 1)) & (POOL_SIZE_BYTES - 1)
+#define CARDS_COUNT POOL_SIZE_BYTES / CARDS_SIZE_BYTES
+
+#define OBJECT_ALLIGNMENT sizeof(size_t)
+#define OBJECT_PTR_MASK ~(OBJECT_ALLIGNMENT - 1)
Index: src/examples/gc_no_raii/src/internal/object_header.h
===================================================================
--- src/examples/gc_no_raii/src/internal/object_header.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/object_header.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -6,22 +6,27 @@
 #include "tools.h"
 
-static const void* CANARY_VALUE = (void*)0xCAFEBABACAFEBABA;
+#if DEBUG
+	static const void* CANARY_VALUE = (void*)0xCAFEBABACAFEBABA;
+#endif
 
 struct gcpointer_t;
+struct gc_object_header;
 
 struct gc_object_header
 {
-	#if _DEBUG
+	#if DEBUG
 		void* canary_start;
 	#endif
 
-	size_t				size;
-	gcpointer_t* 			root_chain;
-	gcpointer_t*			type_chain;
-	struct gc_object_header*	forward;
-	bool					is_forwarded;
+	size_t		size;
+	gcpointer_t* 	root_chain;
+	gcpointer_t*	type_chain;
+	gc_object_header*	forward;
+	bool			is_forwarded;
 
-	#if _DEBUG
+	#if DEBUG
 		void* canary_end;
 	#endif
 };
+
+gc_object_header* gc_object_header_placement_ctor(void* address, size_t size);
Index: src/examples/gc_no_raii/src/internal/state.c
===================================================================
--- src/examples/gc_no_raii/src/internal/state.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/state.c	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -1,9 +1,6 @@
-#include "state.hpp"
-
-#include <algorithm>
-#include <iostream>
+#include "state.h"
 
 //general purpouse includes
-#include "tools.hpp"
+#include "tools.h"
 
 //platform abstraction includes
@@ -11,266 +8,266 @@
 
 //gc internal includes
-#include "globals.hpp"
-#include "memory_pool.hpp"
-#include "memory_pool_iterator.hpp"
-#include "object_header.hpp"
-
-void swap(gc_state* state);
-void sweep_roots(worklist_t worklist);
-void clear(gc_state* state);
-void calc_usage(gc_state* state);
-
-#if DEBUG
-	bool roots_match(gc_state* state);
-	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);
-}
-
-bool state::is_in_heap(void* address) const
-{
-	memory_pool* target_pool = pool_of(address);
-
-	auto first = pools_table.cbegin();
-	auto last = pools_table.cend();
-	auto result = std::find(first, last, target_pool);
-	return result != last && (*result)->is_from_space();
-}
-
-bool state::is_in_to_space(void* address) const
-{
-	const memory_pool* target_pool = pool_of(address);
-
-	auto first = pools_table.cbegin();
-	auto last = pools_table.cend();
-	auto result = std::find(first, last, target_pool);
-	return result != last && !(*result)->is_from_space();
-}
-
-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;
-}
-
-void* state::try_allocate(size_t size)
-{
-	memory_pool* pool = from_space;
-	while(pool)
-	{
-		if(pool->size_left() > size)
-		{
-			return pool->allocate(size, true);
-		}
-		pool = pool->next();
-	}
-
-	return nullptr;
-}
-
-void state::allocate_pool()
-{
-	memory_pool* old_from_space = from_space;
-      memory_pool* old_to_space = to_space;
-
-      from_space = reinterpret_cast<memory_pool*>(pal_allocPool(POOL_SIZE_BYTES, 1));
-      to_space = reinterpret_cast<memory_pool*>(pal_allocPool(POOL_SIZE_BYTES, 1));
-
-      new (from_space) memory_pool(POOL_SIZE_BYTES, old_from_space, to_space, from_code);
-      new (to_space) memory_pool(POOL_SIZE_BYTES, old_to_space, from_space, (~from_code) & 0x01);
-
-	total_space += from_space->size();
-
-	pools_table.push_back(from_space);
-	pools_table.push_back(to_space);
-}
-
-void state::collect()
-{
-	DEBUG("collecting");
-	DEBUG("previous usage " << used_space << " / " << total_space);
-
-	std::vector<void**> worklist;
-	sweep_roots(worklist);
-
-	while(!worklist.empty())
-	{
-		void** ref = worklist.back();
-		worklist.pop_back();
-		process_reference(ref, worklist);
-	}
-
-	check(roots_match());
-	check(no_from_space_ref());
-
-	swap();
-
-	calc_usage();
-
-	if(needs_collect()) allocate_pool();
-
-	DEBUG("done");
-}
-
-void state::swap()
-{
-	std::swap(from_space, to_space);
-
-	memory_pool* pool = to_space;
-	while(pool)
-	{
-		pool->reset();
-		pool = pool->next();
-	}
-
-	from_code = (~from_code) & 0x01;
-
-	#if _DEBUG
-		{
-			memory_pool* pool = from_space;
-			while(pool)
-			{
-				check(pool->is_from_space());
-				pool = pool->next();
-			}
-
-			pool = to_space;
-			while(pool)
-			{
-				check(!pool->is_from_space());
-				pool = pool->next();
-			}
-		}
-	#endif
-}
-
-void state::sweep_roots(std::vector<void**>& worklist)
-{
-	memory_pool* pool = from_space;
-	while(pool)
-	{
-		for(object_header* object : *pool)
-		{
-			if(!object->root_chain) continue;
-
-			copy_object(object);
-
-			scan_object(object->forward, worklist);
-		}
-
-		pool = pool->next();
-	}
-}
-
-void state::clear()
-{
-	memory_pool* pool = from_space;
-	while(pool)
-	{
-		pool->reset();
-		pool = pool->next();
-	}
-
-	pool = to_space;
-	while(pool)
-	{
-		pool->reset();
-		pool = pool->next();
-	}
-}
-
-void state::calc_usage()
-{
-	total_space = 0;
-	used_space = 0;
-
-	memory_pool* pool = from_space;
-	while(pool)
-	{
-		size_t size = pool->size();
-		size_t used = size - pool->size_left();
-		check(used <= size);
-		total_space += size;
-		used_space += used;
-
-		pool = pool->next();
-	}
-}
-
-#if _DEBUG
-	bool state::roots_match()
-	{
-		memory_pool* pool = to_space;
-		while(pool)
-		{
-			size_t size = 0;
-			for(object_header* object : *pool)
-			{
-				size += object->size;
-
-				gcpointer_base* ptr = object->root_chain;
-				while(ptr)
-				{
-					check(get_object_ptr(ptr->m_ptr) == object);
-					ptr = ptr->m_next;
-				}
-			}
-
-			check(size + pool->size_left() == pool->size());
-
-			pool = pool->next();
-		}
-
-		return true;
-	}
-
-	bool state::no_from_space_ref()
-	{
-		memory_pool* pool = to_space;
-		while(pool)
-		{
-			void** potential_ref = (void**)pool->m_start;
-			while(potential_ref < (void**)pool->m_free)
-			{
-				check(!is_in_heap(*potential_ref));
-				potential_ref++;
-			}
-
-			pool = pool->next();
-		}
-
-		return true;
-	}
-#endif
+// #include "globals.h"
+// #include "memory_pool.h"
+// #include "memory_pool_iterator.h"
+// #include "object_header.h"
+//
+// void swap(gc_state* state);
+// void sweep_roots(worklist_t worklist);
+// void clear(gc_state* state);
+// void calc_usage(gc_state* state);
+//
+// #if DEBUG
+// 	bool roots_match(gc_state* state);
+// 	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);
+// }
+//
+// bool state::is_in_heap(void* address) const
+// {
+// 	memory_pool* target_pool = pool_of(address);
+//
+// 	auto first = pools_table.cbegin();
+// 	auto last = pools_table.cend();
+// 	auto result = std::find(first, last, target_pool);
+// 	return result != last && (*result)->is_from_space();
+// }
+//
+// bool state::is_in_to_space(void* address) const
+// {
+// 	const memory_pool* target_pool = pool_of(address);
+//
+// 	auto first = pools_table.cbegin();
+// 	auto last = pools_table.cend();
+// 	auto result = std::find(first, last, target_pool);
+// 	return result != last && !(*result)->is_from_space();
+// }
+//
+// 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;
+// }
+//
+// void* state::try_allocate(size_t size)
+// {
+// 	memory_pool* pool = from_space;
+// 	while(pool)
+// 	{
+// 		if(pool->size_left() > size)
+// 		{
+// 			return pool->allocate(size, true);
+// 		}
+// 		pool = pool->next();
+// 	}
+//
+// 	return nullptr;
+// }
+//
+// void state::allocate_pool()
+// {
+// 	memory_pool* old_from_space = from_space;
+//       memory_pool* old_to_space = to_space;
+//
+//       from_space = reinterpret_cast<memory_pool*>(pal_allocPool(POOL_SIZE_BYTES, 1));
+//       to_space = reinterpret_cast<memory_pool*>(pal_allocPool(POOL_SIZE_BYTES, 1));
+//
+//       new (from_space) memory_pool(POOL_SIZE_BYTES, old_from_space, to_space, from_code);
+//       new (to_space) memory_pool(POOL_SIZE_BYTES, old_to_space, from_space, (~from_code) & 0x01);
+//
+// 	total_space += from_space->size();
+//
+// 	pools_table.push_back(from_space);
+// 	pools_table.push_back(to_space);
+// }
+//
+// void state::collect()
+// {
+// 	DEBUG("collecting");
+// 	DEBUG("previous usage " << used_space << " / " << total_space);
+//
+// 	std::vector<void**> worklist;
+// 	sweep_roots(worklist);
+//
+// 	while(!worklist.empty())
+// 	{
+// 		void** ref = worklist.back();
+// 		worklist.pop_back();
+// 		process_reference(ref, worklist);
+// 	}
+//
+// 	check(roots_match());
+// 	check(no_from_space_ref());
+//
+// 	swap();
+//
+// 	calc_usage();
+//
+// 	if(needs_collect()) allocate_pool();
+//
+// 	DEBUG("done");
+// }
+//
+// void state::swap()
+// {
+// 	std::swap(from_space, to_space);
+//
+// 	memory_pool* pool = to_space;
+// 	while(pool)
+// 	{
+// 		pool->reset();
+// 		pool = pool->next();
+// 	}
+//
+// 	from_code = (~from_code) & 0x01;
+//
+// 	#if _DEBUG
+// 		{
+// 			memory_pool* pool = from_space;
+// 			while(pool)
+// 			{
+// 				check(pool->is_from_space());
+// 				pool = pool->next();
+// 			}
+//
+// 			pool = to_space;
+// 			while(pool)
+// 			{
+// 				check(!pool->is_from_space());
+// 				pool = pool->next();
+// 			}
+// 		}
+// 	#endif
+// }
+//
+// void state::sweep_roots(std::vector<void**>& worklist)
+// {
+// 	memory_pool* pool = from_space;
+// 	while(pool)
+// 	{
+// 		for(object_header* object : *pool)
+// 		{
+// 			if(!object->root_chain) continue;
+//
+// 			copy_object(object);
+//
+// 			scan_object(object->forward, worklist);
+// 		}
+//
+// 		pool = pool->next();
+// 	}
+// }
+//
+// void state::clear()
+// {
+// 	memory_pool* pool = from_space;
+// 	while(pool)
+// 	{
+// 		pool->reset();
+// 		pool = pool->next();
+// 	}
+//
+// 	pool = to_space;
+// 	while(pool)
+// 	{
+// 		pool->reset();
+// 		pool = pool->next();
+// 	}
+// }
+//
+// void state::calc_usage()
+// {
+// 	total_space = 0;
+// 	used_space = 0;
+//
+// 	memory_pool* pool = from_space;
+// 	while(pool)
+// 	{
+// 		size_t size = pool->size();
+// 		size_t used = size - pool->size_left();
+// 		check(used <= size);
+// 		total_space += size;
+// 		used_space += used;
+//
+// 		pool = pool->next();
+// 	}
+// }
+//
+// #if _DEBUG
+// 	bool state::roots_match()
+// 	{
+// 		memory_pool* pool = to_space;
+// 		while(pool)
+// 		{
+// 			size_t size = 0;
+// 			for(object_header* object : *pool)
+// 			{
+// 				size += object->size;
+//
+// 				gcpointer_base* ptr = object->root_chain;
+// 				while(ptr)
+// 				{
+// 					check(get_object_ptr(ptr->m_ptr) == object);
+// 					ptr = ptr->m_next;
+// 				}
+// 			}
+//
+// 			check(size + pool->size_left() == pool->size());
+//
+// 			pool = pool->next();
+// 		}
+//
+// 		return true;
+// 	}
+//
+// 	bool state::no_from_space_ref()
+// 	{
+// 		memory_pool* pool = to_space;
+// 		while(pool)
+// 		{
+// 			void** potential_ref = (void**)pool->m_start;
+// 			while(potential_ref < (void**)pool->m_free)
+// 			{
+// 				check(!is_in_heap(*potential_ref));
+// 				potential_ref++;
+// 			}
+//
+// 			pool = pool->next();
+// 		}
+//
+// 		return true;
+// 	}
+// #endif
Index: src/examples/gc_no_raii/src/internal/state.h
===================================================================
--- src/examples/gc_no_raii/src/internal/state.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/state.h	(revision 6be0cf9f958cd6a2f2ed0607c27023b9a65c146e)
@@ -20,14 +20,14 @@
 };
 
-void gc_state_ctor(gc_state* state);
+void gc_state_ctor(struct gc_state* state);
 
-inline gc_state* get_state()
+static inline gc_state* gc_get_state()
 {
 	static gc_state s;
-	if(!s.is_initialized) gc_state_ctor(s);
+	if(!s.is_initialized) gc_state_ctor(&s);
 	return &s;
 }
 
-inline bool needs_collect(gc_state* state)
+inline bool gc_needs_collect(gc_state* state)
 {
 	return state->used_space * 2 > state->total_space;
