1 module yu.memory.allocator;
2 
3 public import std.experimental.allocator;
4 import std.traits;
5 import std.range;
6 import std.compiler;
7 
8 static if(version_minor > 74) {
9 //    pragma(msg,"__VERSION__ > 2074");
10     alias YuAlloctor = shared ISharedAllocator;
11 } else {
12     alias YuAlloctor = IAllocator;
13 }
14 
15 shared static this() {
16     _yuAlloctor = processAllocator;
17 }
18 
19 @property YuAlloctor yuAlloctor() {
20     return _yuAlloctor;
21 }
22 
23 @property void yuAlloctor(YuAlloctor alloctor) {
24     _yuAlloctor = alloctor;
25 }
26 
27 auto yNew(T, A...)(A args) {
28     return make!(T, YuAlloctor, A)(_yuAlloctor, args);
29 }
30 
31 void yDel(T)(T* p) {
32     dispose!(YuAlloctor, T)(_yuAlloctor, p);
33 }
34 
35 void yDel(T)(T p) if (is(T == class) || is(T == interface)) {
36     dispose!(YuAlloctor, T)(_yuAlloctor, p);
37 }
38 
39 void yDel(T)(T[] array) {
40     dispose!(YuAlloctor, T)(_yuAlloctor, array);
41 }
42 
43 T[] yNewArray(T)(size_t length) {
44     return makeArray!(T, YuAlloctor)(_yuAlloctor, length);
45 }
46 
47 T[] yNewArray(T)(size_t length, auto ref T init) {
48     return makeArray!(T)(_yuAlloctor, length, init);
49 }
50 
51 Unqual!(ElementEncodingType!R)[] yNewArray(R)(R range) if (isInputRange!R && !isInfinite!R) {
52     return makeArray!(YuAlloctor, R)(_yuAlloctor, range);
53 }
54 
55 T[] yNewArray(T, R)(R range) if (isInputRange!R && !isInfinite!R) {
56     return makeArray!(T, YuAlloctor, R)(_yuAlloctor, range);
57 }
58 
59 private:
60 __gshared YuAlloctor _yuAlloctor;