1 /*
2  * Collie - An asynchronous event-driven network framework using Dlang development
3  *
4  * Copyright (C) 2015-2017  Shanghai Putao Technology Co., Ltd 
5  *
6  * Developer: putao's Dlang team
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 module collie.utils.memory;
12 
13 import core.memory;
14 
15 import std.traits;
16 
17 pragma(inline, true) void gcFree(T)(T obj) if (is(T == class) || is(T == interface))
18 {
19     destroy(obj);
20     GC.free(cast(void*) obj);
21 }
22 
23 pragma(inline, true) void gcFree(T)(T* obj)
24 {
25     static if (is(T == struct)) //NOTE: when it call in dstor, the struct's ~this will exec twice.
26         destroy((*obj));
27     GC.free(obj);
28 }
29 
30 pragma(inline, true) void gcFree(void[] obj, bool index = false)
31 {
32     void* t = obj.ptr;
33 	if(t) {
34 	    if (index)
35 	        t = GC.addrOf(t);
36 	    GC.free(t);
37 	}
38 }